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); }
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, }); }
public static Task AsTask(this Operation operation) { return(Task.Factory.StartNew(() => { if (operation.Succeeded == false) { throw operation.GetException(); } })); }
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); } }
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; })); }
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)); }
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)); }
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 }); }
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, }); }
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 }); }
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 }); }
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, }); }