示例#1
0
        public static IRollbackActionResult <TOut> Bind <TIn, TOut>(
            this IRollbackAction <TIn, TOut> action, IRollbackActionResult <TIn> parameter)
        {
            action.ThrowIfNull(nameof(action));
            parameter.ThrowIfNull(nameof(parameter));

            switch (parameter)
            {
            case FailedResult failedResult:
            {
                throw failedResult.Exception.Rethrow();
            }

            case SuccessfulResult <TIn> successfulResult:
            {
                try
                {
                    TOut result = action.Execute(successfulResult.Result);
                    return(new SuccessfulResult <TOut>(
                               result, successfulResult.RollbackList.Prepend(action)
                               ));
                }
                catch (Exception)
                {
                    successfulResult.RollbackList.TryRollbackSafe();
                    throw;
                }
            }

            default:
            {
                throw new ArgumentException("Invalid parameter.", nameof(parameter));
            }
            }
        }
示例#2
0
 public static IRollbackActionResult <TOut> Bind <TIn, TOut>(
     this IRollbackActionResult <TIn> parameter, IRollbackAction <TIn, TOut> action)
 {
     return(Bind(action, parameter));
 }