コード例 #1
0
ファイル: UnWrap.cs プロジェクト: odytrice/Operation
 public static T Unwrap <T>(this Operation <T> operation, string message = null)
 {
     if (operation.Succeeded == false)
     {
         throw (message == null)
             ? operation.GetException()
             : new Exception(message, operation.GetException());
     }
     return(operation.Result);
 }
コード例 #2
0
ファイル: Linq.cs プロジェクト: odytrice/Operation
 public static Operation <V> SelectMany <T, U, V>(this Operation <T> operation, Func <T, Operation <U> > process, Func <T, U, V> projection)
 {
     if (operation.Succeeded)
     {
         var op2 = process(operation.Result);
         if (op2.Succeeded)
         {
             return(Operation.Create(() => projection(operation.Result, op2.Result)));
         }
         else
         {
             return(new Operation <V>(op2.GetException())
             {
                 Succeeded = false,
                 Message = op2.Message,
                 Result = default(V)
             });
         }
     }
     return(new Operation <V>(operation.GetException())
     {
         Succeeded = false,
         Result = default(V),
         Message = operation.Message,
     });
 }
コード例 #3
0
 public static Task AsTask(this Operation operation)
 {
     return(Task.Factory.StartNew(() =>
     {
         if (operation.Succeeded == false)
         {
             throw operation.GetException();
         }
     }));
 }
コード例 #4
0
ファイル: UnWrap.cs プロジェクト: FSharpDeveloper/Operation
 public static void Unwrap(this Operation operation, string message = null)
 {
     message = message ?? operation.Message;
     if (operation.Succeeded == false)
     {
         throw (message == null)
             ? operation.GetException()
             : new Exception(message);
     }
 }
コード例 #5
0
 public static Task <T> AsTask <T>(this Operation <T> operation)
 {
     return(Task <T> .Factory.StartNew(() =>
     {
         if (operation.Succeeded == false)
         {
             throw operation.GetException();
         }
         return operation.Result;
     }));
 }
コード例 #6
0
ファイル: LinqSugar.cs プロジェクト: ebi-igweze/Operation
        public static Operation <T> Select <T>(this Operation operation, Func <object, T> process)
        {
            var op1 = new Operation <object>(operation.GetException())
            {
                Message   = operation.Message,
                Result    = null,
                Succeeded = operation.Succeeded
            };

            return(OperationExtensions.Next(op1, process));
        }
コード例 #7
0
ファイル: LinqSugar.cs プロジェクト: ebi-igweze/Operation
        public static Operation <U> SelectMany <T, U>(this Operation operation, Func <object, Operation <T> > process, Func <object, T, U> projection)
        {
            var op1 = new Operation <object>(operation.GetException())
            {
                Message   = operation.Message,
                Result    = null,
                Succeeded = operation.Succeeded
            };

            return(SelectMany(op1, process, projection));
        }
コード例 #8
0
 public static Operation <U> Next <T, U>(this Operation <T> operation, Func <T, U> process)
 {
     if (operation.Succeeded)
     {
         return(Operation.Create(() => process(operation.Result)));
     }
     return(new Operation <U>(operation.GetException())
     {
         Succeeded = false,
         Result = default(U),
         Message = operation.Message
     });
 }
コード例 #9
0
 public static Operation <T> Next <T>(this Operation operation, Func <T> process)
 {
     if (operation.Succeeded)
     {
         return(Operation.Create(process));
     }
     return(new Operation <T>(operation.GetException())
     {
         Succeeded = false,
         Result = default(T),
         Message = operation.Message,
     });
 }
コード例 #10
0
 public static Operation <T> Bind <T>(this Operation operation, Func <Operation <T> > process)
 {
     if (operation.Succeeded)
     {
         return(process());
     }
     return(new Operation <T>(operation.GetException())
     {
         Succeeded = false,
         Result = default(T),
         Message = operation.Message
     });
 }
コード例 #11
0
ファイル: Linq.cs プロジェクト: odytrice/Operation
 public static Operation <IEnumerable <V> > SelectMany <T, U, V>(this Operation <T> operation, Func <T, IEnumerable <U> > process, Func <T, U, V> projection)
 {
     if (operation.Succeeded)
     {
         var op2 = Operation.Create(() => process(operation.Result));
         return(op2.Next((enumerable) => enumerable.Select(x => projection(operation.Result, x))));
     }
     return(new Operation <IEnumerable <V> >(operation.GetException())
     {
         Succeeded = false,
         Result = default(IEnumerable <V>),
         Message = operation.Message
     });
 }
コード例 #12
0
ファイル: LinqSugar.cs プロジェクト: ebi-igweze/Operation
        public static Operation <U> SelectMany <T, U>(this Operation <T> operation, Func <T, Operation> process, Func <T, object, U> projection)
        {
            if (operation.Succeeded)
            {
                var op2 = process(operation.Result);
                return(op2.Next(() => projection(operation.Result, null)));
            }

            return(new Operation <U>(operation.GetException())
            {
                Succeeded = false,
                Result = default(U),
                Message = operation.Message,
            });
        }