I have something similar to Søren's method in my S...
# social
a
I have something similar to Søren's method in my Skybrud.Essentials package: https://github.com/skybrud/Skybrud.Essentials/blob/34643c8aebd2c498dd923ca01d99e8e7e4b0db9a/src/Skybrud.Essentials/Strings/Extensions/StringExtensions.cs#L111-L132 There is also a method overload with an out parameter that returns the input value as is - this may be convenient if say the input value comes from a method call. E.g.:
Copy code
csharp
if (SomeMethod().HasValue(out string? result)) {
}
instead of:
Copy code
csharp
string? result = SomeMethod();

if (result.HasValue()) {
}
Umbraco by the way also has
IsNullOrWhiteSpace
and similar extension methods for
string
- opposed to using the normal static methods on the
string
class. IIRC it does exactly the same as Søren's and my
HasValue
method.
2 Views