Class NullableExtensions
- Namespace
- Songhay.Extensions
- Assembly
- SonghayCore.dll
Extensions of Nullable
types.
public static class NullableExtensions
- Inheritance
-
NullableExtensions
- Inherited Members
Methods
IsAssignableToISerializable<T>(T?)
Determines whether the specified type can be assigned to ISerializable.
public static bool IsAssignableToISerializable<T>(this T? nullable)
Parameters
nullable
Tthe nullable
Returns
- bool
true
if the specified throw exception is serializable; otherwise,false
.
Type Parameters
T
the specified type
Remarks
For detail, see https://stackoverflow.com/a/945528/22944. For background, see https://manski.net/2014/10/net-serializers-comparison-chart/ and https://github.com/BryanWilhite/SonghayCore/issues/76
Round(decimal?, int)
Rounds the specified decimal.
public static decimal Round(this decimal? nullable, int decimals)
Parameters
Returns
Remarks
For more detail see http://anderly.com/2009/08/08/silverlight-midpoint-rounding-solution/
ThrowWhenNullOrEmpty<T>(IEnumerable<T>?, string?)
Throws an ArgumentNullException when the specified enumerable is null or empty.
public static void ThrowWhenNullOrEmpty<T>(this IEnumerable<T>? enumerable, string? paramName = null)
Parameters
enumerable
IEnumerable<T>the IEnumerable<T>
paramName
stringthe name of the variable holding the IEnumerable<T>
Type Parameters
T
the type of the IEnumerable<T>
ThrowWhenNullOrWhiteSpace(string?, string?)
Throws an ArgumentNullException
when IsNullOrWhiteSpace(string) is true
.
public static void ThrowWhenNullOrWhiteSpace(this string? nullable, string? paramName = null)
Parameters
Remarks
This member borrows heavily from ThrowIfNull(object, string).
The NotNullAttribute is applied to this member based on the following statement from Microsoft:
“Callers can pass a variable with the null nullable, but the argument is guaranteed to never be null if the method returns without throwing an exception.”
[ see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/nullable-analysis#postconditions-maybenull-and-notnull ]
ToObjectOrDbNull<T>(T?)
public static object ToObjectOrDbNull<T>(this T? nullable)
Parameters
nullable
Tthe nullable
Returns
Type Parameters
T
ToReferenceTypeValueOrThrow<T>(T?, string?)
Returns the non-null value of the specified, nullable reference type or throws an ArgumentNullException when the value is null.
public static T ToReferenceTypeValueOrThrow<T>(this T? nullable, string? paramName = null) where T : class?
Parameters
nullable
Tthe nullable
paramName
stringthe name of the variable holding the nullable
Returns
- T
Type Parameters
T
the type
Remarks
This member borrows heavily from ThrowIfNull(object, string).
The NotNullAttribute is applied to this member based on the following statement from Microsoft:
“Callers can pass a variable with the null nullable, but the argument is guaranteed to never be null if the method returns without throwing an exception.”
[ see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/nullable-analysis#postconditions-maybenull-and-notnull ]
ToValueOrThrow<T>(T?, string?)
Returns the non-null value of the specified value type or throws an ArgumentNullException when the value is null.
public static T ToValueOrThrow<T>(this T? nullable, string? paramName = null) where T : struct
Parameters
nullable
T?the nullable
paramName
stringthe name of the variable holding the nullable
Returns
- T
Type Parameters
T
the type
Remarks
This member borrows heavily from ThrowIfNull(object, string).
The NotNullAttribute is applied to this member based on the following statement from Microsoft:
“Callers can pass a variable with the null nullable, but the argument is guaranteed to never be null if the method returns without throwing an exception.”
[ see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/nullable-analysis#postconditions-maybenull-and-notnull ]