using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DG.Core { public static class SystemKeyExtensions { /// /// If extensions /// /// /// /// /// /// public static T If(this T t, bool condition, Action action) where T : class { if (condition) { action(t); } return t; } /// /// If extensions /// /// /// /// /// /// public static T If(this T t, Predicate predicate, Action action) where T : class { if (t == null) { throw new ArgumentNullException(); } if (predicate(t)) { action(t); } return t; } /// /// If extensions /// /// /// /// /// /// public static T If(this T t, bool condition, Func func) where T : class => condition ? func(t) : t; /// /// If extensions /// /// /// /// /// /// public static T If(this T t, Predicate predicate, Func func) where T : class => predicate(t) ? func(t) : t; /// /// If and else extensions /// /// /// /// /// /// /// public static T IfAndElse(this T t, bool condition, Action ifAction, Action elseAction) where T : class { if (condition) { ifAction(t); } else { elseAction(t); } return t; } /// /// If and else extensions /// /// /// /// /// /// /// public static T IfAndElse(this T t, Predicate predicate, Action ifAction, Action elseAction) where T : class { if (t == null) { throw new ArgumentNullException(); } if (predicate(t)) { ifAction(t); } else { elseAction(t); } return t; } /// /// If and else extensions /// /// /// /// /// /// /// public static T IfAndElse(this T t, bool condition, Func ifFunc, Func elseFunc) where T : class => condition ? ifFunc(t) : elseFunc(t); /// /// If and else extensions /// /// /// /// /// /// /// public static T IfAndElse(this T t, Predicate predicate, Func ifFunc, Func elseFunc) where T : class => predicate(t) ? ifFunc(t) : elseFunc(t); } }