public static Task <OperationResult <T> > RequireAsync <T>(this OperationResult <T> currentOperationResult, AsyncPredicate <OperationResult <T> > condition, AsyncFunc <OperationResult <T>, IOperationError> errorBuilder)
 => currentOperationResult
 .DoWhenAsync(async x => !await condition.AssertNotNull(nameof(condition))
              .Invoke(x),
              async x => OperationResult <T> .FromError(
                  await errorBuilder.AssertNotNull(nameof(errorBuilder))
                  .Invoke(x)));
 public static OperationResult <T> Require <T>(this OperationResult <T> currentOperationResult, Predicate <OperationResult <T> > condition, Func <OperationResult <T>, IOperationError> errorBuilder)
 => currentOperationResult
 .DoWhen(x => !condition.AssertNotNull(nameof(condition))
         .Invoke(x),
         x => OperationResult <T> .FromError(
             errorBuilder.AssertNotNull(nameof(errorBuilder))
             .Invoke(x)));
 public static OperationResult Require(this OperationResult currentOperationResult, Predicate condition, Func <IOperationError> errorBuilder)
 => currentOperationResult
 .DoWhen(() => !condition.AssertNotNull(nameof(condition))
         .Invoke(),
         () => OperationResult.FromError(
             errorBuilder.AssertNotNull(nameof(errorBuilder))
             .Invoke()));
 public static Task <OperationResult> RequireAsync(this OperationResult currentOperationResult, Predicate <OperationResult> condition, AsyncFunc <IOperationError> errorBuilder)
 => currentOperationResult
 .DoWhenAsync(x => !condition.AssertNotNull(nameof(condition))
              .Invoke(x),
              async() => OperationResult.FromError(
                  await errorBuilder.AssertNotNull(nameof(errorBuilder))
                  .Invoke()));
 public static Task <OperationResult <T> > RequireOnSuccessAsync <T>(this OperationResult <T> currentOperationResult, bool condition, AsyncFunc <T, IOperationError> errorBuilder)
 => currentOperationResult
 .DoOnSuccessWhenAsync(!condition,
                       async(T x) => OperationResult.FromError(await errorBuilder.AssertNotNull(nameof(errorBuilder))
                                                               .Invoke(x)));
 public static OperationResult RequireOnSuccess(this OperationResult currentOperationResult, bool condition, Func <IOperationError> errorBuilder)
 => currentOperationResult
 .DoOnSuccessWhen(!condition,
                  () => OperationResult.FromError(errorBuilder.AssertNotNull(nameof(errorBuilder))
                                                  .Invoke()));
 public static Task <OperationResult> RequireOnSuccessAsync(this OperationResult currentOperationResult, AsyncPredicate condition, AsyncFunc <IOperationError> errorBuilder)
 => currentOperationResult
 .DoOnSuccessWhenAsync(async() => !await condition.AssertNotNull(nameof(condition))
                       .Invoke(),
                       async() => OperationResult.FromError(await errorBuilder.AssertNotNull(nameof(errorBuilder))
                                                            .Invoke()));
 public static OperationResult <T> RequireOnSuccess <T>(this OperationResult <T> currentOperationResult, Predicate <T> condition, Func <IOperationError> errorBuilder)
 => currentOperationResult
 .DoOnSuccessWhen((T x) => !condition.AssertNotNull(nameof(condition))
                  .Invoke(x),
                  () => OperationResult.FromError(errorBuilder.AssertNotNull(nameof(errorBuilder))
                                                  .Invoke()));
 public static OperationResult Require(this OperationResult currentOperationResult, bool condition, Func <OperationResult, IOperationError> errorBuilder)
 => currentOperationResult
 .DoWhen(!condition,
         x => OperationResult.FromError(
             errorBuilder.AssertNotNull(nameof(errorBuilder))
             .Invoke(x)));
 public static Task <OperationResult> RequireAsync(this OperationResult currentOperationResult, bool condition, AsyncFunc <OperationResult, IOperationError> errorBuilder)
 => currentOperationResult
 .DoWhenAsync(!condition,
              async x => OperationResult.FromError(
                  await errorBuilder.AssertNotNull(nameof(errorBuilder))
                  .Invoke(x)));
Ejemplo n.º 11
0
 public static OperationResult <TResult> Combine <T1, T2, TResult>(OperationResult <T1> operationResult1, OperationResult <T2> operationResult2, Func <T1, T2, TResult> combiner)
 => operationResult1.AssertNotNull(nameof(operationResult1)).IsFailure ? OperationResult <TResult> .FromError(operationResult1.Error)
         : operationResult2.AssertNotNull(nameof(operationResult2)).IsFailure ? OperationResult <TResult> .FromError(operationResult2.Error)
         : OperationResult <TResult> .FromResult(combiner.AssertNotNull(nameof(combiner)).Invoke(operationResult1.Value, operationResult2.Value));