/// <summary> /// If true... /// </summary> /// <param name="this"></param> /// <param name="action"></param> public static void IfFalse <T>(this BooleanVal <T> @this, Action <T> action) { if ([email protected]) { action?.Invoke(@this.Object); } }
public static BooleanVal <T> IfFalseThenInvoke <T>(this BooleanVal <T> @this, Func <T, bool> func) { if ([email protected]) { @this = func?.Invoke(@this.Object) ?? false; } return(@this); }
public static BooleanVal <T> IfTrueThenInvoke <T>(this BooleanVal <T> @this, Func <bool> func) { if (@this.Value) { @this = func?.Invoke() ?? false; } return(@this); }
/// <summary> /// If this then that... /// </summary> /// <typeparam name="TValue"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="condition"></param> /// <param name="this"></param> /// <param name="that"></param> /// <returns></returns> public static TValue Ifttt <T, TValue>(this BooleanVal <T> condition, Func <T, TValue> @this, Func <T, TValue> @that) { if (condition.Value) { return(@this is null ? default : @this.Invoke(condition.Object)); } else { return(that is null ? default : that.Invoke(condition.Object)); } }
/// <summary> /// If this then that... /// </summary> /// <param name="condition"></param> /// <param name="this"></param> /// <param name="that"></param> public static void Ifttt <T>(this BooleanVal <T> condition, Action @this, Action that) { if (condition.Value) { @this?.Invoke(); } else { that?.Invoke(); } }
public static void IfFalseThenThrow <T, TException>(this BooleanVal <T> @this, Dictionary <string, IArgDescriptionVal> exceptionParams) where TException : Exception { @this.IfFalse(_ => ExceptionBuilder.Create <TException>().BuildAndThrow(exceptionParams)); }
public static void IfFalseThenThrow <T, TException>(this BooleanVal <T> @this) where TException : Exception { @this.IfFalse(_ => ExceptionBuilder.Create <TException>().BuildAndThrow()); }
public static BooleanVal <T> Of <T>(bool value, T obj) => BooleanVal <T> .Of(value, obj);
/// <summary> /// If true then throw exception /// </summary> /// <param name="this"></param> /// <param name="exception"></param> public static void IfTrueThenThrow <T>(this BooleanVal <T> @this, Exception exception) { @this.IfTrue(_ => ExceptionHelper.PrepareForRethrow(exception)); }
/// <summary> /// If false then throw exception /// </summary> /// <param name="this"></param> /// <param name="exceptionFunc"></param> public static void IfFalseThenThrow <T>(this BooleanVal <T> @this, Func <T, Exception> exceptionFunc) { @this.IfFalse(val => ExceptionHelper.PrepareForRethrow(exceptionFunc.Invoke(val))); }