Class ResultExtension
Reads a use case out loud: OnSuccess / OnSuccessNull / OnSuccessNotNull / OnFailed describe what happens to a FluentResults.Result without the caller writing a single if statement.
Two rules keep that readability honest:
- A method named *Async always returns a Task or a ValueTask, so the caller must await it. Nothing in this class ever blocks on a Task (no .Wait(), no .Result).
- A method NOT named *Async never accepts an asynchronous callback. Passing one is a compile error pointing at the *Async twin, because an async lambda bound to an Action would run as 'async void': fire-and-forget, with nothing awaiting it. Its exception would then surface on a thread pool thread instead of at the caller's await.
The *Async twins take Task-returning callbacks. Adapt a ValueTask-returning call with an async lambda ('async () => await SaveAsync()') or with .AsTask(): a second overload taking Func<ValueTask> would make every async lambda ambiguous.
None of these methods turns an exception thrown by a callback into a failed Result: the exception propagates to the caller. Use FluentResults' Result.Try for that conversion.
public static class ResultExtension
- Inheritance
-
ResultExtension
- Inherited Members
Examples
Task<Result<Order>> GetOrderAsync(int id) => ...;
var globalResult = Result.Ok();
var result = await GetOrderAsync(42)
.OnSuccessNotNull(order => Console.WriteLine($"Order {order.Id} found"))
.OnSuccessNull(() => Console.WriteLine("No such order"))
.OnFailed(globalResult)
.LogIfFailed();
Methods
LogIfFailed(Task<Result>, LogLevel)
Awaits the task, then passes the result and logLevel to the FluentResults logger when the result is failed.
public static Task<Result> LogIfFailed(this Task<Result> result, LogLevel logLevel = LogLevel.Error)
Parameters
resultTask<Result>The task producing the result to inspect.
logLevelLogLevelThe level handed to the result logger. Defaults to Error.
Returns
- Task<Result>
A task completing with the awaited result, unchanged.
Remarks
It calls the instance method LogIfFailed(LogLevel) of the FluentResults result, which hands the failed result and the level to the IResultLogger configured with Result.Setup (see AddResultLogger); nothing is logged when none is configured. Arc4u's FluentLogger logs each error at logLevel, except a ValidationError (logged at the level of its severity) and an exceptional error (logged as an exception). The original result is returned unchanged.
LogIfFailed(ValueTask<Result>, LogLevel)
Awaits the value task, then passes the result and logLevel to the FluentResults logger when the result is failed.
public static ValueTask<Result> LogIfFailed(this ValueTask<Result> result, LogLevel logLevel = LogLevel.Error)
Parameters
resultValueTask<Result>The value task producing the result to inspect.
logLevelLogLevelThe level handed to the result logger. Defaults to Error.
Returns
- ValueTask<Result>
A value task completing with the awaited result, unchanged.
Remarks
It calls the instance method LogIfFailed(LogLevel) of the FluentResults result, which hands the failed result and the level to the IResultLogger configured with Result.Setup (see AddResultLogger); nothing is logged when none is configured. Arc4u's FluentLogger logs each error at logLevel, except a ValidationError (logged at the level of its severity) and an exceptional error (logged as an exception). The original result is returned unchanged.
LogIfFailed<TValue>(Task<Result<TValue>>, LogLevel)
Awaits the task, then passes the result and logLevel to the FluentResults logger when the result is failed.
public static Task<Result<TValue>> LogIfFailed<TValue>(this Task<Result<TValue>> result, LogLevel logLevel = LogLevel.Error)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
logLevelLogLevelThe level handed to the result logger. Defaults to Error.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
It calls the instance method LogIfFailed(LogLevel) of the FluentResults result, which hands the failed result and the level to the IResultLogger configured with Result.Setup (see AddResultLogger); nothing is logged when none is configured. Arc4u's FluentLogger logs each error at logLevel, except a ValidationError (logged at the level of its severity) and an exceptional error (logged as an exception). The original result is returned unchanged.
LogIfFailed<TValue>(ValueTask<Result<TValue>>, LogLevel)
Awaits the value task, then passes the result and logLevel to the FluentResults logger when the result is failed.
public static ValueTask<Result<TValue>> LogIfFailed<TValue>(this ValueTask<Result<TValue>> result, LogLevel logLevel = LogLevel.Error)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
logLevelLogLevelThe level handed to the result logger. Defaults to Error.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
It calls the instance method LogIfFailed(LogLevel) of the FluentResults result, which hands the failed result and the level to the IResultLogger configured with Result.Setup (see AddResultLogger); nothing is logged when none is configured. Arc4u's FluentLogger logs each error at logLevel, except a ValidationError (logged at the level of its severity) and an exceptional error (logged as an exception). The original result is returned unchanged.
OnFailed(Result, Result)
Copies the errors of the result into globalResult when the result is failed.
public static Result OnFailed(this Result result, Result globalResult)
Parameters
resultResultThe result to inspect.
globalResultResultThe result that collects the errors of the failed result.
Returns
- Result
The
resultreceived, unchanged.
Remarks
Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed(Result, Action<IReadOnlyCollection<IError>>)
Invokes the callback with the errors of the result when the result is failed.
public static Result OnFailed(this Result result, Action<IReadOnlyCollection<IError>> action)
Parameters
resultResultThe result to inspect.
actionAction<IReadOnlyCollection<IError>>The callback receiving the errors of the failed result.
Returns
- Result
The
resultreceived, unchanged.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnFailed(Task<Result>, Result)
Awaits the task, then copies the errors of the result into globalResult when the result is failed.
public static Task<Result> OnFailed(this Task<Result> result, Result globalResult)
Parameters
resultTask<Result>The task producing the result to inspect.
globalResultResultThe result that collects the errors of the failed result.
Returns
- Task<Result>
A task completing with the awaited result, unchanged.
Remarks
Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed(Task<Result>, Action<IReadOnlyCollection<IError>>)
Awaits the task, then invokes the callback with the errors of the result when the result is failed.
public static Task<Result> OnFailed(this Task<Result> result, Action<IReadOnlyCollection<IError>> action)
Parameters
resultTask<Result>The task producing the result to inspect.
actionAction<IReadOnlyCollection<IError>>The callback receiving the errors of the failed result.
Returns
- Task<Result>
A task completing with the awaited result, unchanged.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnFailed(ValueTask<Result>, Result)
Awaits the value task, then copies the errors of the result into globalResult when the result is failed.
public static ValueTask<Result> OnFailed(this ValueTask<Result> result, Result globalResult)
Parameters
resultValueTask<Result>The value task producing the result to inspect.
globalResultResultThe result that collects the errors of the failed result.
Returns
- ValueTask<Result>
A value task completing with the awaited result, unchanged.
Remarks
Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed(ValueTask<Result>, Action<IReadOnlyCollection<IError>>)
Awaits the value task, then invokes the callback with the errors of the result when the result is failed.
public static ValueTask<Result> OnFailed(this ValueTask<Result> result, Action<IReadOnlyCollection<IError>> action)
Parameters
resultValueTask<Result>The value task producing the result to inspect.
actionAction<IReadOnlyCollection<IError>>The callback receiving the errors of the failed result.
Returns
- ValueTask<Result>
A value task completing with the awaited result, unchanged.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnFailedAsync(Result, Func<IReadOnlyCollection<IError>, Task>)
Awaits the asynchronous callback with the errors of the result when the result is failed.
public static Task<Result> OnFailedAsync(this Result result, Func<IReadOnlyCollection<IError>, Task> func)
Parameters
resultResultThe result to inspect.
funcFunc<IReadOnlyCollection<IError>, Task>The callback receiving the errors of the failed result.
Returns
- Task<Result>
A task completing with the
resultreceived, unchanged, once the callback has run.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnFailedAsync(Task<Result>, Func<IReadOnlyCollection<IError>, Task>)
Awaits the task, then awaits the asynchronous callback with the errors of the result when the result is failed.
public static Task<Result> OnFailedAsync(this Task<Result> result, Func<IReadOnlyCollection<IError>, Task> func)
Parameters
resultTask<Result>The task producing the result to inspect.
funcFunc<IReadOnlyCollection<IError>, Task>The callback receiving the errors of the failed result.
Returns
- Task<Result>
A task completing with the awaited result, unchanged.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnFailedAsync(ValueTask<Result>, Func<IReadOnlyCollection<IError>, Task>)
Awaits the value task, then awaits the asynchronous callback with the errors of the result when the result is failed.
public static ValueTask<Result> OnFailedAsync(this ValueTask<Result> result, Func<IReadOnlyCollection<IError>, Task> func)
Parameters
resultValueTask<Result>The value task producing the result to inspect.
funcFunc<IReadOnlyCollection<IError>, Task>The callback receiving the errors of the failed result.
Returns
- ValueTask<Result>
A value task completing with the awaited result, unchanged.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnFailedAsync<TValue>(Result<TValue>, Func<IReadOnlyCollection<IError>, Task>)
Awaits the asynchronous callback with the errors of the result when the result is failed.
public static Task<Result<TValue>> OnFailedAsync<TValue>(this Result<TValue> result, Func<IReadOnlyCollection<IError>, Task> func)
Parameters
resultResult<TValue>The result to inspect.
funcFunc<IReadOnlyCollection<IError>, Task>The callback receiving the errors of the failed result.
Returns
- Task<Result<TValue>>
A task completing with the
resultreceived, unchanged, once the callback has run.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnFailedAsync<TValue>(Task<Result<TValue>>, Func<IReadOnlyCollection<IError>, Task>)
Awaits the task, then awaits the asynchronous callback with the errors of the result when the result is failed.
public static Task<Result<TValue>> OnFailedAsync<TValue>(this Task<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Task> func)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
funcFunc<IReadOnlyCollection<IError>, Task>The callback receiving the errors of the failed result.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnFailedAsync<TValue>(ValueTask<Result<TValue>>, Func<IReadOnlyCollection<IError>, Task>)
Awaits the value task, then awaits the asynchronous callback with the errors of the result when the result is failed.
public static ValueTask<Result<TValue>> OnFailedAsync<TValue>(this ValueTask<Result<TValue>> result, Func<IReadOnlyCollection<IError>, Task> func)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
funcFunc<IReadOnlyCollection<IError>, Task>The callback receiving the errors of the failed result.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnFailed<TGlobal>(Result, Result<TGlobal>)
Collects the errors of an untyped result into a typed global one, the synchronous twin of OnFailed<TGlobal>(Task<Result>, Result<TGlobal>).
public static Result OnFailed<TGlobal>(this Result result, Result<TGlobal> globalResult)
Parameters
resultResultThe result to inspect.
globalResultResult<TGlobal>The result that collects the errors of the failed result.
Returns
- Result
The
resultreceived, unchanged.
Type Parameters
TGlobalThe type of the value carried by the global result.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed<TValue>(Result<TValue>, Result)
Collects the errors of a typed result into an untyped global one, the synchronous twin of OnFailed<TValue>(Task<Result<TValue>>, Result).
public static Result<TValue> OnFailed<TValue>(this Result<TValue> result, Result globalResult)
Parameters
resultResult<TValue>The result to inspect.
globalResultResultThe result that collects the errors of the failed result.
Returns
- Result<TValue>
The
resultreceived, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed<TValue>(Result<TValue>, Action<IReadOnlyCollection<IError>>)
Invokes the callback with the errors of the result when the result is failed.
public static Result<TValue> OnFailed<TValue>(this Result<TValue> result, Action<IReadOnlyCollection<IError>> action)
Parameters
resultResult<TValue>The result to inspect.
actionAction<IReadOnlyCollection<IError>>The callback receiving the errors of the failed result.
Returns
- Result<TValue>
The
resultreceived, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnFailed<TValue>(Task<Result<TValue>>, Result)
Awaits the task, then copies the errors of the result into globalResult when the result is failed.
public static Task<Result<TValue>> OnFailed<TValue>(this Task<Result<TValue>> result, Result globalResult)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
globalResultResultThe result that collects the errors of the failed result.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed<TValue>(Task<Result<TValue>>, Action<IReadOnlyCollection<IError>>)
Awaits the task, then invokes the callback with the errors of the result when the result is failed.
public static Task<Result<TValue>> OnFailed<TValue>(this Task<Result<TValue>> result, Action<IReadOnlyCollection<IError>> action)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
actionAction<IReadOnlyCollection<IError>>The callback receiving the errors of the failed result.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnFailed<TGlobal>(Task<Result>, Result<TGlobal>)
Awaits the task, then copies the errors of the result into globalResult when the result is failed.
public static Task<Result> OnFailed<TGlobal>(this Task<Result> result, Result<TGlobal> globalResult)
Parameters
resultTask<Result>The task producing the result to inspect.
globalResultResult<TGlobal>The result that collects the errors of the failed result.
Returns
- Task<Result>
A task completing with the awaited result, unchanged.
Type Parameters
TGlobalThe type of the value carried by the global result.
Remarks
Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed<TValue>(ValueTask<Result<TValue>>, Result)
Awaits the value task, then copies the errors of the result into globalResult when the result is failed.
public static ValueTask<Result<TValue>> OnFailed<TValue>(this ValueTask<Result<TValue>> result, Result globalResult)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
globalResultResultThe result that collects the errors of the failed result.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed<TValue>(ValueTask<Result<TValue>>, Action<IReadOnlyCollection<IError>>)
Awaits the value task, then invokes the callback with the errors of the result when the result is failed.
public static ValueTask<Result<TValue>> OnFailed<TValue>(this ValueTask<Result<TValue>> result, Action<IReadOnlyCollection<IError>> action)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
actionAction<IReadOnlyCollection<IError>>The callback receiving the errors of the failed result.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped when the result is successful. The original result is always returned unchanged. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnFailed<TGlobal>(ValueTask<Result>, Result<TGlobal>)
Collects the errors of an untyped result into a typed global one, the ValueTask twin of OnFailed<TGlobal>(Task<Result>, Result<TGlobal>).
public static ValueTask<Result> OnFailed<TGlobal>(this ValueTask<Result> result, Result<TGlobal> globalResult)
Parameters
resultValueTask<Result>The value task producing the result to inspect.
globalResultResult<TGlobal>The result that collects the errors of the failed result.
Returns
- ValueTask<Result>
A value task completing with the awaited result, unchanged.
Type Parameters
TGlobalThe type of the value carried by the global result.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed<TValue, TGlobal>(Result<TValue>, Result<TGlobal>)
Copies the errors of the result into globalResult when the result is failed.
public static Result<TValue> OnFailed<TValue, TGlobal>(this Result<TValue> result, Result<TGlobal> globalResult)
Parameters
resultResult<TValue>The result to inspect.
globalResultResult<TGlobal>The result that collects the errors of the failed result.
Returns
- Result<TValue>
The
resultreceived, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
TGlobalThe type of the value carried by the global result.
Remarks
Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed<TValue, TGlobal>(Task<Result<TValue>>, Result<TGlobal>)
Awaits the task, then copies the errors of the result into globalResult when the result is failed.
public static Task<Result<TValue>> OnFailed<TValue, TGlobal>(this Task<Result<TValue>> result, Result<TGlobal> globalResult)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
globalResultResult<TGlobal>The result that collects the errors of the failed result.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
TGlobalThe type of the value carried by the global result.
Remarks
Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.
Exceptions
- ArgumentNullException
globalResultis null.
OnFailed<TValue, TGlobal>(ValueTask<Result<TValue>>, Result<TGlobal>)
Awaits the value task, then copies the errors of the result into globalResult when the result is failed.
public static ValueTask<Result<TValue>> OnFailed<TValue, TGlobal>(this ValueTask<Result<TValue>> result, Result<TGlobal> globalResult)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
globalResultResult<TGlobal>The result that collects the errors of the failed result.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
TGlobalThe type of the value carried by the global result.
Remarks
Use it to aggregate the errors of several steps into a single result. The original result is returned unchanged.
Exceptions
- ArgumentNullException
globalResultis null.
OnSuccess(Result, Action)
Invokes the callback only when the result is successful.
public static Result OnSuccess(this Result result, Action action)
Parameters
resultResultThe result to inspect.
actionActionThe callback to run.
Returns
- Result
The
resultreceived, unchanged.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccess(Task<Result>, Action)
Awaits the task, then invokes the callback only when the result is successful.
public static Task<Result> OnSuccess(this Task<Result> result, Action action)
Parameters
Returns
- Task<Result>
A task completing with the awaited result, unchanged.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccess(ValueTask<Result>, Action)
Awaits the value task, then invokes the callback only when the result is successful.
public static ValueTask<Result> OnSuccess(this ValueTask<Result> result, Action action)
Parameters
resultValueTask<Result>The value task producing the result to inspect.
actionActionThe callback to run.
Returns
- ValueTask<Result>
A value task completing with the awaited result, unchanged.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccessAsync(Result, Func<Task>)
Awaits the asynchronous callback only when the result is successful.
public static Task<Result> OnSuccessAsync(this Result result, Func<Task> func)
Parameters
Returns
- Task<Result>
A task completing with the
resultreceived, unchanged, once the callback has run.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessAsync(Task<Result>, Func<Task>)
Awaits the task, then awaits the asynchronous callback only when the result is successful.
public static Task<Result> OnSuccessAsync(this Task<Result> result, Func<Task> func)
Parameters
Returns
- Task<Result>
A task completing with the awaited result, unchanged.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessAsync(ValueTask<Result>, Func<Task>)
Awaits the value task, then awaits the asynchronous callback only when the result is successful.
public static ValueTask<Result> OnSuccessAsync(this ValueTask<Result> result, Func<Task> func)
Parameters
resultValueTask<Result>The value task producing the result to inspect.
funcFunc<Task>The callback to run.
Returns
- ValueTask<Result>
A value task completing with the awaited result, unchanged.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessAsync<TValue>(Result<TValue>, Func<Task>)
Awaits the asynchronous callback only when the result is successful.
public static Task<Result<TValue>> OnSuccessAsync<TValue>(this Result<TValue> result, Func<Task> func)
Parameters
Returns
- Task<Result<TValue>>
A task completing with the
resultreceived, unchanged, once the callback has run.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessAsync<TValue>(Result<TValue>, Func<TValue, Task>)
Awaits the asynchronous callback, passing it the value of the result only when the result is successful.
public static Task<Result<TValue>> OnSuccessAsync<TValue>(this Result<TValue> result, Func<TValue, Task> func)
Parameters
resultResult<TValue>The result to inspect.
funcFunc<TValue, Task>The callback receiving the value of the result.
Returns
- Task<Result<TValue>>
A task completing with the
resultreceived, unchanged, once the callback has run.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessAsync<TValue>(Task<Result<TValue>>, Func<Task>)
Awaits the task, then awaits the asynchronous callback only when the result is successful.
public static Task<Result<TValue>> OnSuccessAsync<TValue>(this Task<Result<TValue>> result, Func<Task> func)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
funcFunc<Task>The callback to run.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task>)
Awaits the task, then awaits the asynchronous callback, passing it the value of the result only when the result is successful.
public static Task<Result<TValue>> OnSuccessAsync<TValue>(this Task<Result<TValue>> result, Func<TValue, Task> func)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
funcFunc<TValue, Task>The callback receiving the value of the result.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessAsync<TValue>(ValueTask<Result<TValue>>, Func<Task>)
Awaits the value task, then awaits the asynchronous callback only when the result is successful.
public static ValueTask<Result<TValue>> OnSuccessAsync<TValue>(this ValueTask<Result<TValue>> result, Func<Task> func)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
funcFunc<Task>The callback to run.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, Task>)
Awaits the value task, then awaits the asynchronous callback, passing it the value of the result only when the result is successful.
public static ValueTask<Result<TValue>> OnSuccessAsync<TValue>(this ValueTask<Result<TValue>> result, Func<TValue, Task> func)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
funcFunc<TValue, Task>The callback receiving the value of the result.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNotNullAsync<TValue>(Result<TValue>, Func<Task>)
Awaits the asynchronous callback only when the result is successful and its value is not null.
public static Task<Result<TValue>> OnSuccessNotNullAsync<TValue>(this Result<TValue> result, Func<Task> func)
Parameters
Returns
- Task<Result<TValue>>
A task completing with the
resultreceived, unchanged, once the callback has run.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNotNullAsync<TValue>(Result<TValue>, Func<TValue, Task>)
Awaits the asynchronous callback, passing it the value of the result only when the result is successful and its value is not null.
public static Task<Result<TValue>> OnSuccessNotNullAsync<TValue>(this Result<TValue> result, Func<TValue, Task> func)
Parameters
resultResult<TValue>The result to inspect.
funcFunc<TValue, Task>The callback receiving the value of the result.
Returns
- Task<Result<TValue>>
A task completing with the
resultreceived, unchanged, once the callback has run.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNotNullAsync<TValue>(Task<Result<TValue>>, Func<Task>)
Awaits the task, then awaits the asynchronous callback only when the result is successful and its value is not null.
public static Task<Result<TValue>> OnSuccessNotNullAsync<TValue>(this Task<Result<TValue>> result, Func<Task> func)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
funcFunc<Task>The callback to run.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNotNullAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task>)
Awaits the task, then awaits the asynchronous callback, passing it the value of the result only when the result is successful and its value is not null.
public static Task<Result<TValue>> OnSuccessNotNullAsync<TValue>(this Task<Result<TValue>> result, Func<TValue, Task> func)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
funcFunc<TValue, Task>The callback receiving the value of the result.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNotNullAsync<TValue>(ValueTask<Result<TValue>>, Func<Task>)
Awaits the value task, then awaits the asynchronous callback only when the result is successful and its value is not null.
public static ValueTask<Result<TValue>> OnSuccessNotNullAsync<TValue>(this ValueTask<Result<TValue>> result, Func<Task> func)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
funcFunc<Task>The callback to run.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNotNullAsync<TValue>(ValueTask<Result<TValue>>, Func<TValue, Task>)
Awaits the value task, then awaits the asynchronous callback, passing it the value of the result only when the result is successful and its value is not null.
public static ValueTask<Result<TValue>> OnSuccessNotNullAsync<TValue>(this ValueTask<Result<TValue>> result, Func<TValue, Task> func)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
funcFunc<TValue, Task>The callback receiving the value of the result.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNotNull<TValue>(Result<TValue>, Action)
Invokes the callback only when the result is successful and its value is not null.
public static Result<TValue> OnSuccessNotNull<TValue>(this Result<TValue> result, Action action)
Parameters
resultResult<TValue>The result to inspect.
actionActionThe callback to run.
Returns
- Result<TValue>
The
resultreceived, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccessNotNull<TValue>(Result<TValue>, Action<TValue>)
Invokes the callback with the value of the result only when the result is successful and its value is not null.
public static Result<TValue> OnSuccessNotNull<TValue>(this Result<TValue> result, Action<TValue> action)
Parameters
resultResult<TValue>The result to inspect.
actionAction<TValue>The callback receiving the value of the result.
Returns
- Result<TValue>
The
resultreceived, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccessNotNull<TValue>(Task<Result<TValue>>, Action)
Awaits the task, then invokes the callback only when the result is successful and its value is not null.
public static Task<Result<TValue>> OnSuccessNotNull<TValue>(this Task<Result<TValue>> result, Action action)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
actionActionThe callback to run.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccessNotNull<TValue>(Task<Result<TValue>>, Action<TValue>)
Awaits the task, then invokes the callback with the value of the result only when the result is successful and its value is not null.
public static Task<Result<TValue>> OnSuccessNotNull<TValue>(this Task<Result<TValue>> result, Action<TValue> action)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
actionAction<TValue>The callback receiving the value of the result.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccessNotNull<TValue>(ValueTask<Result<TValue>>, Action)
Awaits the value task, then invokes the callback only when the result is successful and its value is not null.
public static ValueTask<Result<TValue>> OnSuccessNotNull<TValue>(this ValueTask<Result<TValue>> result, Action action)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
actionActionThe callback to run.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccessNotNull<TValue>(ValueTask<Result<TValue>>, Action<TValue>)
Awaits the value task, then invokes the callback with the value of the result only when the result is successful and its value is not null.
public static ValueTask<Result<TValue>> OnSuccessNotNull<TValue>(this ValueTask<Result<TValue>> result, Action<TValue> action)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
actionAction<TValue>The callback receiving the value of the result.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccessNullAsync<TValue>(Result<TValue>, Func<Task>)
Awaits the asynchronous callback only when the result is successful and its value is null.
public static Task<Result<TValue>> OnSuccessNullAsync<TValue>(this Result<TValue> result, Func<Task> func)
Parameters
Returns
- Task<Result<TValue>>
A task completing with the
resultreceived, unchanged, once the callback has run.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNullAsync<TValue>(Task<Result<TValue>>, Func<Task>)
Awaits the task, then awaits the asynchronous callback only when the result is successful and its value is null.
public static Task<Result<TValue>> OnSuccessNullAsync<TValue>(this Task<Result<TValue>> result, Func<Task> func)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
funcFunc<Task>The callback to run.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNullAsync<TValue>(ValueTask<Result<TValue>>, Func<Task>)
Awaits the value task, then awaits the asynchronous callback only when the result is successful and its value is null.
public static ValueTask<Result<TValue>> OnSuccessNullAsync<TValue>(this ValueTask<Result<TValue>> result, Func<Task> func)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
funcFunc<Task>The callback to run.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
funcis null.
OnSuccessNull<TValue>(Result<TValue>, Action)
Invokes the callback only when the result is successful and its value is null.
public static Result<TValue> OnSuccessNull<TValue>(this Result<TValue> result, Action action)
Parameters
resultResult<TValue>The result to inspect.
actionActionThe callback to run.
Returns
- Result<TValue>
The
resultreceived, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccessNull<TValue>(Task<Result<TValue>>, Action)
Awaits the task, then invokes the callback only when the result is successful and its value is null.
public static Task<Result<TValue>> OnSuccessNull<TValue>(this Task<Result<TValue>> result, Action action)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
actionActionThe callback to run.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccessNull<TValue>(ValueTask<Result<TValue>>, Action)
Awaits the value task, then invokes the callback only when the result is successful and its value is null.
public static ValueTask<Result<TValue>> OnSuccessNull<TValue>(this ValueTask<Result<TValue>> result, Action action)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
actionActionThe callback to run.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccess<TValue>(Result<TValue>, Action)
Invokes the callback only when the result is successful.
public static Result<TValue> OnSuccess<TValue>(this Result<TValue> result, Action action)
Parameters
resultResult<TValue>The result to inspect.
actionActionThe callback to run.
Returns
- Result<TValue>
The
resultreceived, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccess<TValue>(Result<TValue>, Action<TValue>)
Invokes the callback with the value of the result only when the result is successful.
public static Result<TValue> OnSuccess<TValue>(this Result<TValue> result, Action<TValue> action)
Parameters
resultResult<TValue>The result to inspect.
actionAction<TValue>The callback receiving the value of the result.
Returns
- Result<TValue>
The
resultreceived, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
A successful Result may still carry a null value: use OnSuccessNotNull<TValue>(Result<TValue>, Action<TValue>) when the callback needs a value it can dereference.
Exceptions
- ArgumentNullException
actionis null.
OnSuccess<TValue>(Task<Result<TValue>>, Action)
Awaits the task, then invokes the callback only when the result is successful.
public static Task<Result<TValue>> OnSuccess<TValue>(this Task<Result<TValue>> result, Action action)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
actionActionThe callback to run.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccess<TValue>(Task<Result<TValue>>, Action<TValue>)
Awaits the task, then invokes the callback with the value of the result only when the result is successful.
public static Task<Result<TValue>> OnSuccess<TValue>(this Task<Result<TValue>> result, Action<TValue> action)
Parameters
resultTask<Result<TValue>>The task producing the result to inspect.
actionAction<TValue>The callback receiving the value of the result.
Returns
- Task<Result<TValue>>
A task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccess<TValue>(ValueTask<Result<TValue>>, Action)
Awaits the value task, then invokes the callback only when the result is successful.
public static ValueTask<Result<TValue>> OnSuccess<TValue>(this ValueTask<Result<TValue>> result, Action action)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
actionActionThe callback to run.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.
OnSuccess<TValue>(ValueTask<Result<TValue>>, Action<TValue>)
Awaits the value task, then invokes the callback with the value of the result only when the result is successful.
public static ValueTask<Result<TValue>> OnSuccess<TValue>(this ValueTask<Result<TValue>> result, Action<TValue> action)
Parameters
resultValueTask<Result<TValue>>The value task producing the result to inspect.
actionAction<TValue>The callback receiving the value of the result.
Returns
- ValueTask<Result<TValue>>
A value task completing with the awaited result, unchanged.
Type Parameters
TValueThe type of the value carried by the result.
Remarks
The callback is skipped otherwise. The original result is always returned unchanged, so calls can be chained. An exception thrown by the callback propagates to the caller.
Exceptions
- ArgumentNullException
actionis null.