Table of Contents

Class FromResultToTypedResultExtension

Namespace
Arc4u.AspNetCore.Results
Assembly
Arc4u.AspNetCore.Results.dll

Converts a FluentResults.Result or FluentResults.Result<TValue> (or a task of it) into a typed Results<...> union for minimal API endpoints.

public static class FromResultToTypedResultExtension
Inheritance
FromResultToTypedResultExtension
Inherited Members

Examples

app.MapGet("/orders/{id}", (int id, IOrderService orders) => orders.GetAsync(id).ToTypedOkResultAsync());

Remarks

The ToTypedOkResult family answers Ok<T> (or NoContent for a non-generic FluentResults.Result); the ToTypedCreatedResult family answers Created. A failed result is a ProblemHttpResult built from the ProblemDetails produced by FromResultToProblemDetailExtension. The ValidationProblem member of the union is there so that the endpoint metadata advertises the validation response; the conversion itself only produces a ProblemHttpResult.

The overloads on a Task or ValueTask await it first; the ones on a plain result do not await anything. The overloads with a mapper project the value before it is written to the response.

Methods

ToTypedCreatedResult(Result, Uri?)

Converts the result to a typed Results<...> union (minimal API): 201 Created with the given location on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Results<Created, ProblemHttpResult, ValidationProblem> ToTypedCreatedResult(this Result result, Uri? location)

Parameters

result Result

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Results<Created, ProblemHttpResult, ValidationProblem>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedCreatedResultAsync(Result, Uri?)

Converts the result to a typed Results<...> union (minimal API): 201 Created with the given location on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Created, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync(this Result result, Uri? location)

Parameters

result Result

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Task<Results<Created, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedCreatedResultAsync(Task<Result>, Uri?)

Awaits the task, then converts the result to a typed Results<...> union (minimal API): 201 Created with the given location on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Created, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync(this Task<Result> result, Uri? location)

Parameters

result Task<Result>

The task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Task<Results<Created, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedCreatedResultAsync(ValueTask<Result>, Uri?)

Awaits the value task, then converts the result to a typed Results<...> union (minimal API): 201 Created with the given location on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static ValueTask<Results<Created, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync(this ValueTask<Result> result, Uri? location)

Parameters

result ValueTask<Result>

The value task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

ValueTask<Results<Created, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedCreatedResultAsync<TResult>(Result<TResult>, Uri?)

Converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value of the result on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Created<TResult>, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync<TResult>(this Result<TResult> result, Uri? location)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Task<Results<Created<TResult>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedCreatedResultAsync<TResult>(Task<Result<TResult>>, Uri?)

Awaits the task, then converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value of the result on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Created<TResult>, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync<TResult>(this Task<Result<TResult>> result, Uri? location)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Task<Results<Created<TResult>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedCreatedResultAsync<TResult>(ValueTask<Result<TResult>>, Uri?)

Awaits the value task, then converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value of the result on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static ValueTask<Results<Created<TResult>, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync<TResult>(this ValueTask<Result<TResult>> result, Uri? location)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

ValueTask<Results<Created<TResult>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedCreatedResultAsync<TResult, T>(Result<TResult>, Uri?, Func<TResult, Task<T>>)

Converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value produced by asyncMapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync<TResult, T>(this Result<TResult> result, Uri? location, Func<TResult, Task<T>> asyncMapper)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToTypedCreatedResultAsync<TResult, T>(Result<TResult>, Uri?, Func<TResult, T>)

Converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value produced by mapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync<TResult, T>(this Result<TResult> result, Uri? location, Func<TResult, T> mapper)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToTypedCreatedResultAsync<TResult, T>(Task<Result<TResult>>, Uri?, Func<TResult, Task<T>>)

Awaits the task, then converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value produced by asyncMapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync<TResult, T>(this Task<Result<TResult>> result, Uri? location, Func<TResult, Task<T>> asyncMapper)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToTypedCreatedResultAsync<TResult, T>(Task<Result<TResult>>, Uri?, Func<TResult, T>)

Awaits the task, then converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value produced by mapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync<TResult, T>(this Task<Result<TResult>> result, Uri? location, Func<TResult, T> mapper)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToTypedCreatedResultAsync<TResult, T>(ValueTask<Result<TResult>>, Uri?, Func<TResult, Task<T>>)

Awaits the value task, then converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value produced by asyncMapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Uri? location, Func<TResult, Task<T>> asyncMapper)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<Results<Created<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToTypedCreatedResultAsync<TResult, T>(ValueTask<Result<TResult>>, Uri?, Func<TResult, T>)

Awaits the value task, then converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value produced by mapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static ValueTask<Results<Created<T>, ProblemHttpResult, ValidationProblem>> ToTypedCreatedResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Uri? location, Func<TResult, T> mapper)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

ValueTask<Results<Created<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToTypedCreatedResult<TResult>(Result<TResult>, Uri?)

Converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value of the result on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Results<Created<TResult>, ProblemHttpResult, ValidationProblem> ToTypedCreatedResult<TResult>(this Result<TResult> result, Uri? location)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Results<Created<TResult>, ProblemHttpResult, ValidationProblem>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedCreatedResult<TResult, T>(Result<TResult>, Uri?, Func<TResult, T>)

Converts the result to a typed Results<...> union (minimal API): 201 Created with the given location and the value produced by mapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Results<Created<T>, ProblemHttpResult, ValidationProblem> ToTypedCreatedResult<TResult, T>(this Result<TResult> result, Uri? location, Func<TResult, T> mapper)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

Results<Created<T>, ProblemHttpResult, ValidationProblem>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToTypedOkResult(Result)

Converts the result to a typed Results<...> union (minimal API): 204 No Content on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Results<NoContent, ProblemHttpResult, ValidationProblem> ToTypedOkResult(this Result result)

Parameters

result Result

The result to convert.

Returns

Results<NoContent, ProblemHttpResult, ValidationProblem>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedOkResultAsync(Result)

Converts the result to a typed Results<...> union (minimal API): 204 No Content on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<NoContent, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync(this Result result)

Parameters

result Result

The result to convert.

Returns

Task<Results<NoContent, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedOkResultAsync(Task<Result>)

Awaits the task, then converts the result to a typed Results<...> union (minimal API): 204 No Content on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<NoContent, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync(this Task<Result> result)

Parameters

result Task<Result>

The task producing the result to convert.

Returns

Task<Results<NoContent, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedOkResultAsync(ValueTask<Result>)

Awaits the value task, then converts the result to a typed Results<...> union (minimal API): 204 No Content on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static ValueTask<Results<NoContent, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync(this ValueTask<Result> result)

Parameters

result ValueTask<Result>

The value task producing the result to convert.

Returns

ValueTask<Results<NoContent, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedOkResultAsync<TResult>(Task<Result<TResult>>)

Awaits the task, then converts the result to a typed Results<...> union (minimal API): 200 OK containing the value of the result on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Ok<TResult>, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync<TResult>(this Task<Result<TResult>> result)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

Returns

Task<Results<Ok<TResult>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedOkResultAsync<TResult>(ValueTask<Result<TResult>>)

Awaits the value task, then converts the result to a typed Results<...> union (minimal API): 200 OK containing the value of the result on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static ValueTask<Results<Ok<TResult>, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync<TResult>(this ValueTask<Result<TResult>> result)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

Returns

ValueTask<Results<Ok<TResult>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedOkResultAsync<TResult, T>(Result<TResult>, Func<TResult, Task<T>>)

Converts the result to a typed Results<...> union (minimal API): 200 OK containing the value produced by asyncMapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Ok<T>, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync<TResult, T>(this Result<TResult> result, Func<TResult, Task<T>> asyncMapper)

Parameters

result Result<TResult>

The result to convert.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<Results<Ok<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToTypedOkResultAsync<TResult, T>(Task<Result<TResult>>, Func<TResult, Task<T>>)

Awaits the task, then converts the result to a typed Results<...> union (minimal API): 200 OK containing the value produced by asyncMapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Ok<T>, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync<TResult, T>(this Task<Result<TResult>> result, Func<TResult, Task<T>> asyncMapper)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<Results<Ok<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToTypedOkResultAsync<TResult, T>(Task<Result<TResult>>, Func<TResult, T>)

Awaits the task, then converts the result to a typed Results<...> union (minimal API): 200 OK containing the value produced by mapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Ok<T>, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync<TResult, T>(this Task<Result<TResult>> result, Func<TResult, T> mapper)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

Task<Results<Ok<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToTypedOkResultAsync<TResult, T>(ValueTask<Result<TResult>>, Func<TResult, Task<T>>)

Awaits the value task, then converts the result to a typed Results<...> union (minimal API): 200 OK containing the value produced by asyncMapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Task<Results<Ok<T>, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Func<TResult, Task<T>> asyncMapper)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<Results<Ok<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToTypedOkResultAsync<TResult, T>(ValueTask<Result<TResult>>, Func<TResult, T>)

Awaits the value task, then converts the result to a typed Results<...> union (minimal API): 200 OK containing the value produced by mapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static ValueTask<Results<Ok<T>, ProblemHttpResult, ValidationProblem>> ToTypedOkResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Func<TResult, T> mapper)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

ValueTask<Results<Ok<T>, ProblemHttpResult, ValidationProblem>>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToTypedOkResult<TResult>(Result<TResult>)

Converts the result to a typed Results<...> union (minimal API): 200 OK containing the value of the result on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Results<Ok<TResult>, ProblemHttpResult, ValidationProblem> ToTypedOkResult<TResult>(this Result<TResult> result)

Parameters

result Result<TResult>

The result to convert.

Returns

Results<Ok<TResult>, ProblemHttpResult, ValidationProblem>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToTypedOkResult<TResult, T>(Result<TResult>, Func<TResult, T>)

Converts the result to a typed Results<...> union (minimal API): 200 OK containing the value produced by mapper on success, a ProblemHttpResult built from the ProblemDetails on failure.

public static Results<Ok<T>, ProblemHttpResult, ValidationProblem> ToTypedOkResult<TResult, T>(this Result<TResult> result, Func<TResult, T> mapper)

Parameters

result Result<TResult>

The result to convert.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

Results<Ok<T>, ProblemHttpResult, ValidationProblem>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.