C# BindAsync函数有哪些功能?
BindAsync函数的功能是什么? 我有一个示例方法,它在get all之后使用这个命令C# BindAsync函数有哪些功能?,c#,azure,asynchronous,bind,C#,Azure,Asynchronous,Bind,BindAsync函数的功能是什么? 我有一个示例方法,它在get all之后使用这个命令 public async Task<Either<Exception, List<Clients>>> BuscarClientes() { return await GetAllByAsync(x => true) .BindAsync(clients => { cl
public async Task<Either<Exception, List<Clients>>> BuscarClientes()
{
return await GetAllByAsync(x => true)
.BindAsync(clients =>
{
clients = clients.Where(x => x.active == "S")
.OrderBy(x => x.Name)
return clients
}
}
谁能告诉我这个
BindAsync
方法是做什么的,它是如何工作的?我假设BindAsync
扩展函数来自C#的函数扩展
如文档中所述,该方法的目的是
/// <summary>
/// Transforms the <paramref name="result"/> into another <see cref="Result{T}"/> using the <paramref name="binder"/> function.
/// If the input result is Ok, returns the value of the binder call (which is <see cref="Result{T}"/> of <typeparamref name="TOut"/>).
/// Otherwise returns Error case of the Result of <typeparamref name="TOut"/>.
/// </summary>
/// <typeparam name="TIn">Type of the value in the input result.</typeparam>
/// <typeparam name="TOut">Type of the value in the returned result.</typeparam>
/// <param name="result">The result to bind with.</param>
/// <param name="binder">Function called with the input result value if it's Ok case.</param>
public static async Task<Result<TOut>> BindAsync<TIn, TOut>(this Result<TIn> result, Func<TIn, Task<Result<TOut>>> binder) =>
result.IsOk ? await binder(result.Value) : Error<TOut>(result.Error);
//
///使用函数将转换为另一个。
///如果输入结果正常,则返回绑定器调用的值(为)。
///否则返回的结果的错误大小写。
///
///输入结果中的值的类型。
///返回结果中的值的类型。
///要绑定的结果。
///如果在正常情况下,则使用输入结果值调用函数。
公共静态异步任务BindAsync(此结果,Func binder)=>
结果是什么?等待活页夹(result.Value):错误(result.Error);
这意味着在应用作为活页夹传入的函数后,它将接收传入的异步操作的结果并将其公开,包装在任务中
/// <summary>
/// Transforms the <paramref name="result"/> into another <see cref="Result{T}"/> using the <paramref name="binder"/> function.
/// If the input result is Ok, returns the value of the binder call (which is <see cref="Result{T}"/> of <typeparamref name="TOut"/>).
/// Otherwise returns Error case of the Result of <typeparamref name="TOut"/>.
/// </summary>
/// <typeparam name="TIn">Type of the value in the input result.</typeparam>
/// <typeparam name="TOut">Type of the value in the returned result.</typeparam>
/// <param name="result">The result to bind with.</param>
/// <param name="binder">Function called with the input result value if it's Ok case.</param>
public static async Task<Result<TOut>> BindAsync<TIn, TOut>(this Result<TIn> result, Func<TIn, Task<Result<TOut>>> binder) =>
result.IsOk ? await binder(result.Value) : Error<TOut>(result.Error);