ObjectExtensions Class
Provides extension methods for objects to ensure non-null values.
public static class ObjectExtensionsInheritance System.Object → ObjectExtensions
Methods
ObjectExtensions.NotNull<T>(this Nullable<T>, string) Method
Ensures that the specified nullable value type is not null. Throws an InvalidOperationException if it is null.
public static T NotNull<T>(this System.Nullable<T> value, string valueName)
where T : struct;Type parameters
T
The type of the nullable value type.
Parameters
value System.Nullable<T>
The nullable value type to check for null.
valueName System.String
The name of the nullable value type, which will be used in the exception message if the value is null.
Returns
T
The original non-null value of type T.
Exceptions
System.InvalidOperationException
Thrown when the input value is null.
ObjectExtensions.NotNull<T>(this T, string) Method
Ensures that the specified nullable reference type is not null. Throws an InvalidOperationException if it is null.
public static T NotNull<T>(this T? value, string valueName)
where T : class;Type parameters
T
The type of the nullable reference type.
Parameters
value T
The nullable reference type to check for null.
valueName System.String
The name of the nullable reference type, which will be used in the exception message if the value is null.
Returns
T
The original non-null value of type T.
Exceptions
System.InvalidOperationException
Thrown when the input value is null.
ObjectExtensions.ToAsync<T>(this T) Method
Wraps a single value as an System.Collections.Generic.IAsyncEnumerable<> that yields exactly one element. Useful for adapting non-streaming sources to APIs that consume an async sequence - for example handing a single signing key to a verifier that expects a candidate-key stream.
public static System.Collections.Generic.IAsyncEnumerable<T> ToAsync<T>(this T value);Type parameters
T
The type of the value to wrap.
Parameters
value T
The value to yield.
Returns
System.Collections.Generic.IAsyncEnumerable<T>
An System.Collections.Generic.IAsyncEnumerable<> producing value
once and then completing.