Has(text), Coalesce(a,b,c), list.Where(FilledIn) to replace garbage like !Equals(x, default(T?)) && !Equals(x, default(T)) and string.IsNullOrWhiteSpace(text). Fallbacks, emptiness checks coded like you mean it.
$ dotnet add package JJ.Framework.Existence.CoreEver find yourself trying to decide on IsNullOrEmpty, IsNullOrWhiteSpace, a null check, empty list check or whether you should check at all?
Well, no more. Now you just type Has(text) or Has(collection) and be done with it.
Nothing isn't one thing in .NET. It's null, default, white space, 0, NaN, Empty, Length = 0, !Equals(x, default(T?)) && !Equals(x, default(T)). It gets absurd with the many states of nothingness in .NET.
Here we coin the term nully. Don't blame us; the concept already existed, just nobody gave it a name yet.
Grab these methods instead of wrestling with these checks. Your code (and your brain) will thank you:
Has / FilledIn / IsNully
null treating empty strings / white space / 0 / empty lists as nully.Coalesce
nully value (?? on steroids).In / Contains
Is
Flags for special occasions:
spaceMatters
string is just a single space.zeroMatters
0 meaningful.caseMatters
list = list.Where(FilledIn);
if (number.IsNully()) return;
if (Has(name)) sb.Append($" {name} ");
Coalesce(" ", Null, "Hi!") == "Hi!"
"\r\n GREEN\t ".Is("Green")
"GREEN".In("Red", "Green","Blue") == true!
flex mode – force a full runtime type lookup on values when you're feeling adventurous.char quirks – treat lone ' ' as nully by default (no more sneaky space bugs).float drama – NaN, ∞, +0/–0 all count as empty.enum safety net – invalid enum values get flagged as nully instead of blowing up.null collections – if every item is null, the whole collection is officially empty.Is – 10.Is("10") regardless of type, because how will we stay sane if 10 isn't 10?Links to legacy dependencies may have changed. If you experience problems, these things might help:
12JJ.Framework.Common.Legacy namespace where you currently use JJ.Framework.Common.3JJ.Framework.Common explicitly. You may need a downgrade to a 0.* version.The same thing applies to
JJ.Framework.PlatformCompatibility.Legacy vs JJ.Framework.PlatformCompatibility
2.5 | Initial release | - |
2.6 | Flags | spaceMatters flags everywhere |
caseMatters replaced ignoreCase | ||
StringBulder/string more combos possible | ||
x.In(a, b, c) extension favored over static In(x, a, b, c) | ||
2.7 | Version Lineages + IntelliSense | Improved separation of Legacy version lineages for a more stable package update. |
2.8 | AOT, Trimming & Self-Contained Apps | Compatibility with AOT "Ahead-Of-Time" native compilation, code trimming and single-executable, self-contained apps. |
2.9 | zeroMatters | Flag when you consider 0 meaningful (not nully) |
3.0 | .NET 10 | Upgraded with explicit support for .NET 10 |
3.1 | Less Prios | Simplify overload picking removing some [Prio] attributes. |
Sacrifices direct use of keywords e.g. Coalesce(null, "Hallo"); not a real use case anyway. | ||
3.2 | Leading Flags - Coalesce | Flags at the beginning of the parameter list, now don't come with a performance penalty. |
3.3 | Leading Flags - Contains | More notation options for flags for the Contains method |
3.4 | Leading Flags - FilledIn | Support flags in front for the FilledIn method |
3.7 | Clash of the Booleans | Leading flags for Has/Is/In/IsNully (supplements trailing flags) |
Improved Coalesce resolution and performance for 4+ values and collections. | ||
Added overloads for reduced clashes between bool flags and value lists. | ||
| Various non-critical renames for clarity and modularity. | ||
3.8 | Business.Legacy | Added project properties hardening code trimming and native compile compatibility. |
During a release of another library: JJ.Framework.Business.Legacy |
Special thanks to Mr. Koala. Once you think of koalas when you read 🐨 Coalesce, you can never unsee it. Mr. Koala eats your nullies. Nully nums are his favorite!
Found an issue? Let me know.