/// <summary> /// Run Common If Code Schema with Validation /// Schema : Init --> Pre --> Validate --> /// ((Process or ValidFalse or ValidNull) or Fail) /// --> Post --> End. /// Check methods Init and End methods return bool? results and run CheckTrue/CheckFalse/CheckNull methods if available /// or return default on not true /// </summary> public static ResT I <ParamT, ResT>(Pr <ParamT, ResT> ProcessToRun, Cx CurrCodeType = null) { if (ProcessToRun.V == null && ProcessToRun.Vn == null) { return(ProcessToRun.D); } Pr <ParamT, ResT> Res = ProcessToRun; Res.Vt = (param, code) => { bool?Validated = true; ResT Result = ProcessToRun.D; if (ProcessToRun.V != null) { Validated = ProcessToRun.V(param, CurrCodeType); } if (Validated == null) { if (ProcessToRun.Vn != null) { Result = ProcessToRun.Vn(param, CurrCodeType); } else if (ProcessToRun.F != null) { Result = ProcessToRun.F(param, CurrCodeType); } } else if (Validated == false) { if (ProcessToRun.Vf != null) { Result = ProcessToRun.Vf(param, CurrCodeType); } else if (ProcessToRun.F != null) { Result = ProcessToRun.F(param, CurrCodeType); } } else if (ProcessToRun.Vt != null) { Result = ProcessToRun.Vt(param, CurrCodeType); } else if (ProcessToRun.F != null) { Result = ProcessToRun.F(param, CurrCodeType); } return(Result); }; return(F(Res, CurrCodeType)); }
/// <summary> /// Run Common Try Code Schema with Error Handling /// Schema : Init --> Pre --> Validate --> /// try[CustomUseTryCatch or CurrCodeType] (Process or Fail) with Error OnErrorCatch /// --> Post --> End. /// Check methods Init and End methods return bool? results and run CheckTrue/CheckFalse/CheckNull methods if available /// or return default on not true /// </summary> public static ResT T <ParamT, ResT>(Pr <ParamT, ResT> ProcessToRun, Cx CurrCodeType = null) { bool UseTryCatch = CurrCodeType != null && CurrCodeType.T; Pr <ParamT, ResT> Res = ProcessToRun; Res.Vt = (param, code) => { ResT Result = ProcessToRun.D; if (UseTryCatch) { try { if (ProcessToRun.Vt != null) { Result = ProcessToRun.Vt(param, CurrCodeType); } else { Result = ProcessToRun.F(param, CurrCodeType); } } catch (Exception exc) { Result = ProcessToRun.D; if (ProcessToRun.Er != null) { Result = ProcessToRun.Er(param, Result, exc, CurrCodeType); } } } else if (ProcessToRun.Vt != null) { Result = ProcessToRun.Vt(param, CurrCodeType); } else { Result = ProcessToRun.F(param, CurrCodeType); } return(Result); }; return(F(Res, CurrCodeType)); }
/// <summary> /// Run Common Try Code Schema Block With Errors And Performance Logging based on CurrCodeType. /// Schema : Init --> Pre --> Validate --> /// try[CustomUseTryCatch or CurrCodeType] /// ((Process or ValidFalse or ValidNull) or Fail) with Error OnErrorCatch /// --> Post --> End. /// Check methods Init and End methods return bool? results and run CheckTrue/CheckFalse/CheckNull methods if available /// or return default on not true /// </summary> public static ResT Ti <ParamT, ResT>(Pr <ParamT, ResT> ProcessToRun, Cx CurrCodeType = null) { bool UseTryCatch = CurrCodeType != null && CurrCodeType.T; Pr <ParamT, ResT> Res = ProcessToRun; Res.Vt = (param, code) => { bool?Validated = true; ResT Result = ProcessToRun.D; if (ProcessToRun.V != null) { Validated = ProcessToRun.V(param, CurrCodeType); } if (Validated == null) { if (ProcessToRun.Vn != null) { Result = ProcessToRun.Vn(param, CurrCodeType); } else if (ProcessToRun.F != null) { Result = ProcessToRun.F(param, CurrCodeType); } } else if (Validated == false) { if (ProcessToRun.Vf != null) { Result = ProcessToRun.Vf(param, CurrCodeType); } else if (ProcessToRun.F != null) { Result = ProcessToRun.F(param, CurrCodeType); } } else if (ProcessToRun.Vt != null) { Result = ProcessToRun.Vt(param, CurrCodeType); } else if (ProcessToRun.F != null) { Result = ProcessToRun.F(param, CurrCodeType); } return(Result); }; return(T(Res, CurrCodeType)); }
/// <summary> /// Run Common Code Schema without additional code /// Schema : Init --> Pre --> (Process or Fail) --> Post --> End. /// Check methods Init and End methods return bool? results and run CheckTrue/CheckFalse/CheckNull methods if available /// or return default on not true /// </summary> public static ResT F <ParamT, ResT>(Pr <ParamT, ResT> ProcessToRun, Cx CurrCodeType = null) { if ((ProcessToRun.Vt == null && ProcessToRun.F == null) || ProcessToRun.P == null) { return(ProcessToRun.D); } if (!Code_FuncUtils.E(ProcessToRun, ProcessToRun.I, CurrCodeType)) { return(ProcessToRun.D); } ParamT CurrParam = ProcessToRun.P; if (ProcessToRun.Pe != null) { CurrParam = ProcessToRun.Pe(ProcessToRun.P, CurrCodeType); } ResT Result = ProcessToRun.D; if (ProcessToRun.Vt != null) { Result = ProcessToRun.Vt(ProcessToRun.P, CurrCodeType); } else { Result = ProcessToRun.F(ProcessToRun.P, CurrCodeType); } if (ProcessToRun.Ps != null) { Result = ProcessToRun.Ps(ProcessToRun.P, Result, CurrCodeType); } if (!Code_FuncUtils.E(ProcessToRun, ProcessToRun.E, Result, CurrCodeType)) { return(ProcessToRun.D); } return(Result); }