public static SafeWrapper <T2> OnFailure <T1, T2>(this SafeWrapper <T1> wrapped, Func <SafeWrapper <T1>, T2> func) { if (!AssertNotNull(wrapped, func)) { return(new SafeWrapper <T2>(default(T2), OperationErrorCode.InvalidArgument, new ArgumentException(), "Passed-in function delegate is null")); } SafeWrapperResult result = wrapped; if (!result) { return(SafeWrap(() => func(wrapped))); } return(new SafeWrapper <T2>(default(T2), result)); }
public static async Task <SafeWrapper <T2> > OnFailureAsync <T1, T2>(this Task <SafeWrapper <T1> > wrapped, Func <SafeWrapper <T1>, Task <T2> > func) { if (!AssertNotNull(wrapped, func)) { return(new SafeWrapper <T2>(default(T2), OperationErrorCode.InvalidArgument, new ArgumentException(), "Passed-in function delegate is null")); } SafeWrapperResult result = await wrapped; if (!result) { return(await SafeWrapAsync(() => func(wrapped.Result))); } return(new SafeWrapper <T2>(default(T2), result)); }