Table of Contents

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 T

the nullable

Returns

bool

true if the specified throw exception is serializable; otherwise, false.

Type Parameters

T

the specified type

Remarks

Round(decimal?, int)

Rounds the specified decimal.

public static decimal Round(this decimal? nullable, int decimals)

Parameters

nullable decimal?

The decimal nullable.

decimals int

The decimals.

Returns

decimal

Remarks

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 string

the name of the variable holding the IEnumerable<T>

Type Parameters

T

the type of the IEnumerable<T>

ThrowWhenNullOrWhiteSpace(string?, string?)

public static void ThrowWhenNullOrWhiteSpace(this string? nullable, string? paramName = null)

Parameters

nullable string

the nullable string

paramName string

the name of the variable holding the string

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?)

Boxes the nullable in object or returns DBNull.

public static object ToObjectOrDbNull<T>(this T? nullable)

Parameters

nullable T

the nullable

Returns

object

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 T

the nullable

paramName string

the 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 string

the 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 ]