/// <summary> /// Evaluate common bool? return from CheckToEvaluate with context CheckFalse/CheckNull/CheckTrue methods details /// Returns true if any method return true, else false /// </summary> /// <returns>Returns true if any method return true, else false</returns> public static bool E <ParamT, ResT>(this Pr <ParamT, ResT> CurrProcess, f <ParamT, ResT, Cx, bool?> CheckToEvaluate, ResT ResToEvaluate = default(ResT), Cx CurrCodeType = null, bool EvaluateDefault = true) { if (CheckToEvaluate == null) { return(EvaluateDefault); } bool?Res = CheckToEvaluate(CurrProcess.P, ResToEvaluate, CurrCodeType); if (Res == null && CurrProcess.Cn != null) { return(CurrProcess.Cn(CurrProcess.P, ResToEvaluate, CurrCodeType)); } if (Res == false && CurrProcess.Cf != null) { return(!CurrProcess.Cf(CurrProcess.P, ResToEvaluate, CurrCodeType)); } if (Res == true && CurrProcess.Ct != null) { return(!CurrProcess.Ct(CurrProcess.P, ResToEvaluate, CurrCodeType)); } if (Res == true) { return(true); } return(false); }
/// <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 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 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> /// Create new custom process with specified methods /// </summary> public static Pr <ParamT, ResT> E <ParamT, ResT>(this ParamT StartParam, f <ParamT, Cx, ResT> ProcessFunc, Cx CurrCodeType = null, f <ParamT, Cx, ResT> ProcessFail = null, f <ParamT, ResT, Exception, Cx, ResT> ProcessError = null) { Pr <ParamT, ResT> Result = new Pr <ParamT, ResT>(); Result.P = StartParam; if (ProcessFunc == null) { Result.Vt = ProcessFunc; } if (ProcessFail == null) { Result.F = ProcessFail; } if (ProcessError == null) { Result.Er = ProcessError; } return(Result); }
/// <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); }