Last active
October 24, 2021 08:28
-
-
Save guitarrapc/5ad4a1611f465d3c7ccc674a24be23d1 to your computer and use it in GitHub Desktop.
variations of IsNullPrEmpty in C# ref: https://twitter.com/badamczewski01/status/1449319543336222725?s=20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string? x = null; | |
IsNullOrEmpty(x).Dump(); | |
NullableLength(x).Dump(); | |
PropLength(x).Dump(); | |
TypeOrEmpty(x).Dump(); | |
TypeAndEmpty(x).Dump(); | |
bool IsNullOrEmpty(string? x) => string.IsNullOrEmpty(x); | |
bool NullableLength(string? x) => x?.Length == 0 || x is null; | |
bool PropLength(string? x) => x is not {Length: > 0}; | |
bool TypeOrEmpty(string? x) => x is null or ""; | |
bool TypeAndEmpty(string? x) => x is string and "" or null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment