public static CodeRunResult RunCode(Action code) { try { code(); return(CodeRunResult.SuccessResult()); } catch (Exception exc) { return(CodeRunResult.ErrorResult(exc)); } }
public static CodeRunResult RunCode <TCodeResult>(Func <TCodeResult> code) { try { var result = code(); return(CodeRunResult.SuccessResult(result)); } catch (Exception exc) { return(CodeRunResult.ErrorResult(exc)); } }
public static CodeRunResult RunCode <TErrorResult>(Action code, Func <Exception, TErrorResult> onCodeError) { try { code(); return(CodeRunResult.SuccessResult()); } catch (Exception exc) { var errResult = onCodeError(exc); return(CodeRunResult.ErrorResult(exc, errResult)); } }
public static CodeRunResult ErrorResult(IEnumerable <string> messages, IEnumerable <Exception> exceptions, object data = null) { var msgs = messages?.ToArray(); var excs = exceptions?.ToArray(); var cr = new CodeRunResult { Data = data }; if (msgs != null && msgs.Length > 0) { cr.ErrorMessages = msgs; } if (excs != null && excs.Length > 0) { cr.Exceptions = excs; } return(cr); }