Table of Contents

Class EnsureExtensionsAsync

Namespace
Trellis
Assembly
Trellis.Core.dll

Async Ensure extensions where BOTH input and predicates are async (Task).

public static class EnsureExtensionsAsync
Inheritance
EnsureExtensionsAsync
Inherited Members

Examples

var ct = cancellationToken;
await result.EnsureAsync(
    value => ValidateAsync(value, ct),
    Error.InvalidInput.ForRule(code: "invalid", detail: "Validation failed")
);

Remarks

Users should capture CancellationToken in their lambda closures when cancellation support is needed.

Methods

EnsureAsync<TValue>(Task<Result<TValue>>, Func<bool>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<bool> predicate, Error error)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<bool>

The predicate to test.

error Error

The error to return if the predicate is false.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<Task<Result<TValue>>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<Task<Result<TValue>>> predicate)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<Task<Result<TValue>>>

The async predicate function that returns a Result.

Returns

Task<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<Result<TValue>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<Result<TValue>> predicate)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<Result<TValue>>

The predicate function that returns a Result.

Returns

Task<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<TValue, bool>, Func<TValue, Task<Error>>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result. The error is generated asynchronously.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<TValue, bool> predicate, Func<TValue, Task<Error>> errorPredicate)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<TValue, bool>

The predicate function to test the value.

errorPredicate Func<TValue, Task<Error>>

The async function that generates an error from the value.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<TValue, bool>, Func<TValue, Error>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<TValue, bool> predicate, Func<TValue, Error> errorPredicate)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<TValue, bool>

The predicate function to test the value.

errorPredicate Func<TValue, Error>

The function that generates an error from the value.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<TValue, bool>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<TValue, bool> predicate, Error error)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<TValue, bool>

The predicate function to test the value.

error Error

The error to return if the predicate is false.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task<bool>>, Func<TValue, Task<Error>>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<TValue, Task<bool>> predicate, Func<TValue, Task<Error>> errorPredicate)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<TValue, Task<bool>>

The async predicate to test the value.

errorPredicate Func<TValue, Task<Error>>

The async function that generates an error from the value.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task<bool>>, Func<TValue, Error>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<TValue, Task<bool>> predicate, Func<TValue, Error> errorPredicate)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<TValue, Task<bool>>

The async predicate to test the value.

errorPredicate Func<TValue, Error>

The function that generates an error from the value.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task<bool>>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<TValue, Task<bool>> predicate, Error error)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<TValue, Task<bool>>

The async predicate to test the value.

error Error

The error to return if the predicate is false.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task<Result<TValue>>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<TValue, Task<Result<TValue>>> predicate)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<TValue, Task<Result<TValue>>>

The async predicate function that receives the value and returns a Result.

Returns

Task<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Task<Result<TValue>>, Func<TValue, Result<TValue>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Task<Result<TValue>> resultTask, Func<TValue, Result<TValue>> predicate)

Parameters

resultTask Task<Result<TValue>>

The task containing the result to validate.

predicate Func<TValue, Result<TValue>>

The predicate function that receives the value and returns a Result.

Returns

Task<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<bool>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<bool> predicate, Error error)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<bool>

The predicate to test.

error Error

The error to return if the predicate is false.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<ValueTask<Result<TValue>>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<ValueTask<Result<TValue>>> predicate)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<ValueTask<Result<TValue>>>

The async predicate function that returns a Result.

Returns

ValueTask<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<Result<TValue>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<Result<TValue>> predicate)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<Result<TValue>>

The predicate function that returns a Result.

Returns

ValueTask<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, bool>, Func<TValue, ValueTask<Error>>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<TValue, bool> predicate, Func<TValue, ValueTask<Error>> errorPredicate)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<TValue, bool>

The predicate to test the value.

errorPredicate Func<TValue, ValueTask<Error>>

The async function that generates an error from the value.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, bool>, Func<TValue, Error>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<TValue, bool> predicate, Func<TValue, Error> errorPredicate)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<TValue, bool>

The predicate to test the value.

errorPredicate Func<TValue, Error>

The function that generates an error from the value.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, bool>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<TValue, bool> predicate, Error error)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<TValue, bool>

The predicate to test the value.

error Error

The error to return if the predicate is false.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, ValueTask<bool>>, Func<TValue, ValueTask<Error>>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<TValue, ValueTask<bool>> predicate, Func<TValue, ValueTask<Error>> errorPredicate)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<TValue, ValueTask<bool>>

The async predicate to test the value.

errorPredicate Func<TValue, ValueTask<Error>>

The async function that generates an error from the value.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, ValueTask<bool>>, Func<TValue, Error>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<TValue, ValueTask<bool>> predicate, Func<TValue, Error> errorPredicate)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<TValue, ValueTask<bool>>

The async predicate to test the value.

errorPredicate Func<TValue, Error>

The function that generates an error from the value.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, ValueTask<bool>>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<TValue, ValueTask<bool>> predicate, Error error)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<TValue, ValueTask<bool>>

The async predicate to test the value.

error Error

The error to return if the predicate is false.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, ValueTask<Result<TValue>>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<TValue, ValueTask<Result<TValue>>> predicate)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<TValue, ValueTask<Result<TValue>>>

The async predicate function that receives the value and returns a Result.

Returns

ValueTask<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, Result<TValue>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this ValueTask<Result<TValue>> resultTask, Func<TValue, Result<TValue>> predicate)

Parameters

resultTask ValueTask<Result<TValue>>

The async result to validate.

predicate Func<TValue, Result<TValue>>

The predicate function that receives the value and returns a Result.

Returns

ValueTask<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<Task<bool>>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<Task<bool>> predicate, Error error)

Parameters

result Result<TValue>

The result to validate.

predicate Func<Task<bool>>

The async predicate to test.

error Error

The error to return if the predicate is false.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<Task<Result<TValue>>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<Task<Result<TValue>>> predicate)

Parameters

result Result<TValue>

The result to validate.

predicate Func<Task<Result<TValue>>>

The async predicate function that returns a Result.

Returns

Task<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<ValueTask<bool>>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<ValueTask<bool>> predicate, Error error)

Parameters

result Result<TValue>

The result to validate.

predicate Func<ValueTask<bool>>

The async predicate to test.

error Error

The error to return if the predicate is false.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<ValueTask<Result<TValue>>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<ValueTask<Result<TValue>>> predicate)

Parameters

result Result<TValue>

The result to validate.

predicate Func<ValueTask<Result<TValue>>>

The async predicate function that returns a Result.

Returns

ValueTask<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<TValue, Task<bool>>, Func<TValue, Task<Error>>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<TValue, Task<bool>> predicate, Func<TValue, Task<Error>> errorPredicate)

Parameters

result Result<TValue>

The result to validate.

predicate Func<TValue, Task<bool>>

The async predicate to test the value.

errorPredicate Func<TValue, Task<Error>>

The async function that generates an error from the value.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<TValue, Task<bool>>, Func<TValue, Error>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<TValue, Task<bool>> predicate, Func<TValue, Error> errorPredicate)

Parameters

result Result<TValue>

The result to validate.

predicate Func<TValue, Task<bool>>

The async predicate to test the value.

errorPredicate Func<TValue, Error>

The function that generates an error from the value.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<TValue, Task<bool>>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<TValue, Task<bool>> predicate, Error error)

Parameters

result Result<TValue>

The result to validate.

predicate Func<TValue, Task<bool>>

The async predicate to test the value.

error Error

The error to return if the predicate is false.

Returns

Task<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<TValue, Task<Result<TValue>>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static Task<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<TValue, Task<Result<TValue>>> predicate)

Parameters

result Result<TValue>

The result to validate.

predicate Func<TValue, Task<Result<TValue>>>

The async predicate function that receives the value and returns a Result.

Returns

Task<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<TValue, ValueTask<bool>>, Func<TValue, ValueTask<Error>>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<TValue, ValueTask<bool>> predicate, Func<TValue, ValueTask<Error>> errorPredicate)

Parameters

result Result<TValue>

The result to validate.

predicate Func<TValue, ValueTask<bool>>

The async predicate to test the value.

errorPredicate Func<TValue, ValueTask<Error>>

The async function that generates an error from the value.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<TValue, ValueTask<bool>>, Func<TValue, Error>)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<TValue, ValueTask<bool>> predicate, Func<TValue, Error> errorPredicate)

Parameters

result Result<TValue>

The result to validate.

predicate Func<TValue, ValueTask<bool>>

The async predicate to test the value.

errorPredicate Func<TValue, Error>

The function that generates an error from the value.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<TValue, ValueTask<bool>>, Error)

Returns a new failure result if the predicate is false. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<TValue, ValueTask<bool>> predicate, Error error)

Parameters

result Result<TValue>

The result to validate.

predicate Func<TValue, ValueTask<bool>>

The async predicate to test the value.

error Error

The error to return if the predicate is false.

Returns

ValueTask<Result<TValue>>

The original result if success and predicate is true; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureAsync<TValue>(Result<TValue>, Func<TValue, ValueTask<Result<TValue>>>)

Returns a new failure result if the predicate result is a failure. Otherwise returns the starting result.

public static ValueTask<Result<TValue>> EnsureAsync<TValue>(this Result<TValue> result, Func<TValue, ValueTask<Result<TValue>>> predicate)

Parameters

result Result<TValue>

The result to validate.

predicate Func<TValue, ValueTask<Result<TValue>>>

The async predicate function that receives the value and returns a Result.

Returns

ValueTask<Result<TValue>>

The original result if both succeed; otherwise a failure.

Type Parameters

TValue

Type of the result value.

EnsureNotNullAsync<T>(Task<T?>, Func<Error>)

Awaits a nullable struct once, creating an error only for a null result.

public static Task<Result<T>> EnsureNotNullAsync<T>(this Task<T?> task, Func<Error> errorFactory) where T : struct

Parameters

task Task<T?>
errorFactory Func<Error>

Returns

Task<Result<T>>

Type Parameters

T

Remarks

Task and factory are validated before awaiting. Source and factory exceptions propagate.

EnsureNotNullAsync<T>(Task<T?>, string?, string?)

Awaits a nullable struct once, creating a required-field error only for a null result.

public static Task<Result<T>> EnsureNotNullAsync<T>(this Task<T?> task, string? fieldName, string? detail = null) where T : struct

Parameters

task Task<T?>
fieldName string
detail string

Returns

Task<Result<T>>

Type Parameters

T

Remarks

The field name and detail follow Required(string?, string?). Source faults and cancellation propagate.

EnsureNotNullAsync<T>(Task<T?>, Error)

Awaits a nullable struct once, returning its unwrapped value or the supplied error.

public static Task<Result<T>> EnsureNotNullAsync<T>(this Task<T?> task, Error error) where T : struct

Parameters

task Task<T?>
error Error

Returns

Task<Result<T>>

Type Parameters

T

Remarks

A null task throws. Source faults and cancellation propagate unchanged.

EnsureNotNullAsync<T>(Task<T?>, Func<Error>)

Awaits a nullable reference once, creating an error only for a null result.

public static Task<Result<T>> EnsureNotNullAsync<T>(this Task<T?> task, Func<Error> errorFactory) where T : class

Parameters

task Task<T>
errorFactory Func<Error>

Returns

Task<Result<T>>

Type Parameters

T

Remarks

Task and factory are validated before awaiting. Source and factory exceptions propagate.

EnsureNotNullAsync<T>(Task<T?>, string?, string?)

Awaits a nullable reference once, creating a required-field error only for a null result.

public static Task<Result<T>> EnsureNotNullAsync<T>(this Task<T?> task, string? fieldName, string? detail = null) where T : class

Parameters

task Task<T>
fieldName string
detail string

Returns

Task<Result<T>>

Type Parameters

T

Remarks

The field name and detail follow Required(string?, string?). Source faults and cancellation propagate.

EnsureNotNullAsync<T>(Task<T?>, Error)

Awaits a nullable reference once, returning its non-null value or the supplied error.

public static Task<Result<T>> EnsureNotNullAsync<T>(this Task<T?> task, Error error) where T : class

Parameters

task Task<T>
error Error

Returns

Task<Result<T>>

Type Parameters

T

Remarks

A null task throws. Source faults and cancellation propagate unchanged.

EnsureNotNullAsync<T>(ValueTask<T?>, Func<Error>)

Awaits a nullable struct once, creating an error only for a null result.

public static ValueTask<Result<T>> EnsureNotNullAsync<T>(this ValueTask<T?> task, Func<Error> errorFactory) where T : struct

Parameters

task ValueTask<T?>
errorFactory Func<Error>

Returns

ValueTask<Result<T>>

Type Parameters

T

Remarks

The factory is validated before awaiting. Source and factory exceptions propagate.

EnsureNotNullAsync<T>(ValueTask<T?>, string?, string?)

Awaits a nullable struct once, creating a required-field error only for a null result.

public static ValueTask<Result<T>> EnsureNotNullAsync<T>(this ValueTask<T?> task, string? fieldName, string? detail = null) where T : struct

Parameters

task ValueTask<T?>
fieldName string
detail string

Returns

ValueTask<Result<T>>

Type Parameters

T

Remarks

The field name and detail follow Required(string?, string?). Source faults and cancellation propagate.

EnsureNotNullAsync<T>(ValueTask<T?>, Error)

Awaits a nullable struct once, returning its unwrapped value or the supplied error.

public static ValueTask<Result<T>> EnsureNotNullAsync<T>(this ValueTask<T?> task, Error error) where T : struct

Parameters

task ValueTask<T?>
error Error

Returns

ValueTask<Result<T>>

Type Parameters

T

Remarks

Source faults and cancellation propagate unchanged.

EnsureNotNullAsync<T>(ValueTask<T?>, Func<Error>)

Awaits a nullable reference once, creating an error only for a null result.

public static ValueTask<Result<T>> EnsureNotNullAsync<T>(this ValueTask<T?> task, Func<Error> errorFactory) where T : class

Parameters

task ValueTask<T>
errorFactory Func<Error>

Returns

ValueTask<Result<T>>

Type Parameters

T

Remarks

The factory is validated before awaiting. Source and factory exceptions propagate.

EnsureNotNullAsync<T>(ValueTask<T?>, string?, string?)

Awaits a nullable reference once, creating a required-field error only for a null result.

public static ValueTask<Result<T>> EnsureNotNullAsync<T>(this ValueTask<T?> task, string? fieldName, string? detail = null) where T : class

Parameters

task ValueTask<T>
fieldName string
detail string

Returns

ValueTask<Result<T>>

Type Parameters

T

Remarks

The field name and detail follow Required(string?, string?). Source faults and cancellation propagate.

EnsureNotNullAsync<T>(ValueTask<T?>, Error)

Awaits a nullable reference once, returning its non-null value or the supplied error.

public static ValueTask<Result<T>> EnsureNotNullAsync<T>(this ValueTask<T?> task, Error error) where T : class

Parameters

task ValueTask<T>
error Error

Returns

ValueTask<Result<T>>

Type Parameters

T

Remarks

Source faults and cancellation propagate unchanged.