public static bool IsMatch <T>(this T subject, T target, CompareGuardTypes compareType) where T : IComparable <T> { var compare = subject.CompareTo(target); switch (compareType) { case CompareGuardTypes.GreaterThan: return(compare > 0); case CompareGuardTypes.Equals: return(compare == 0); case CompareGuardTypes.NotEquals: return(compare != 0); case CompareGuardTypes.LessThan: return(compare < 0); case CompareGuardTypes.GreaterOrEqualThan: return(compare >= 0); case CompareGuardTypes.LessOrEqualThan: default: return(compare <= 0); } }
public AsyncCompareGuard(Task <T> subject, T target, CompareGuardTypes type) : base(subject) { this.target = target; CompareType = type; }
/// <summary> /// builds an async comparison guard for the subject /// </summary> /// <typeparam name="T">result type of the subject task</typeparam> /// <param name="subject">The subject to guard/param> /// <param name="target">the target to compare against</param> /// <param name="compareType">the type of comparison to do against the target. See <see cref="CompareGuardTypes"/></param> /// <returns>an instance of <see cref="IAsyncCompareGuard{T}"/> that will guard the subject </returns> public static IAsyncCompareGuard <T> Compare <T>(this Task <T> subject, T target, CompareGuardTypes compareType) where T : IComparable <T> => new AsyncCompareGuard <T>(subject, target, compareType);