/// <summary>Returns null if <paramref name="self" /> is <see cref="String.IsNullOrEmpty" />.</summary>
/// <param name="self"></param>
/// <returns></returns>
[CanBeNull]
[DebuggerStepThrough]
[Pure]
public static String? NullIfEmpty( [CanBeNull] this String? self ) => String.IsNullOrEmpty( self ) ? null : self;
Category: How To
How to Trim whitespace from a String in C#
/// <summary>Trim the ToString() of the object; returning null if null, empty, or whitespace.</summary>
/// <param name="self"></param>
/// <returns></returns>
[DebuggerStepThrough]
[CanBeNull]
[Pure]
public static String? Trimmed<T>( [CanBeNull] this T self ) =>
self switch {
null => default( String? ),
String s => s.Trim().NullIfEmpty(),
var _ => self.ToString()?.Trim().NullIfEmpty()
};
How to convert a Guid to BigInteger in C#
[DebuggerStepThrough]
[Pure]
public static BigInteger ToBigInteger( this Guid self ) => new( self.ToByteArray() );