using System; namespace ScreenConnect; public static class ResultExtensions { public static TResult Unwrap(this Result @this) where TError : Exception { return @this.UnwrapOrElse(delegate(TError it) { throw it; }); } public static bool Try(Proc proc, Func exceptionHandler, out TError errorResult) { return ResultExtensions.Try(proc, exceptionHandler, out errorResult); } public static bool Try(Proc proc, Func exceptionHandler, out TError errorResult) where TException : Exception { try { proc(); } catch (TException arg) { errorResult = exceptionHandler(arg); return false; } errorResult = default(TError); return true; } public static Result TryGetResult(Func func, bool traceException = true) { try { return func(); } catch (Exception ex) { if (traceException) { TypeTrace.TraceException(ex); } return ex; } } }