diff --git a/X10D/src/ComparableExtensions.cs b/X10D/src/ComparableExtensions.cs deleted file mode 100644 index 3ff2ed1..0000000 --- a/X10D/src/ComparableExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; - -namespace X10D -{ - /// - /// Extension methods for . - /// - public static class ComparableExtensions - { - /// - /// Determines if is between and . - /// - /// The comparable type. - /// The value to compare. - /// The exclusive lower bound. - /// The exclusive upper bound. - /// - /// Returns if the value is between the bounds, - /// otherwise. - /// - public static bool Between(this T actual, T lower, T upper) - where T : IComparable - { - return actual.CompareTo(lower) > 0 && actual.CompareTo(upper) < 0; - } - } -} diff --git a/X10D/src/ComparableExtensions/ComparableExtensions.cs b/X10D/src/ComparableExtensions/ComparableExtensions.cs new file mode 100644 index 0000000..d357e9d --- /dev/null +++ b/X10D/src/ComparableExtensions/ComparableExtensions.cs @@ -0,0 +1,54 @@ +using System; +using System.Runtime.CompilerServices; + +namespace X10D.ComparableExtensions +{ + /// + /// Extension methods for . + /// + public static partial class ComparableExtensions + { + /// + /// Determines if is between and . + /// + /// An type. + /// The first comparison operand type. + /// The second comparison operand type. + /// The value to compare. + /// The exclusive lower bound. + /// The exclusive upper bound. + /// + /// if is between the and + /// + /// -or- + /// otherwise. + /// + /// + /// + /// int firstValue = 42; + /// int secondValue = 15; + /// + /// int lower = 0; + /// int upper = 20; + /// + /// Console.WriteLine($"{firstValue} between {lower} and {upper}?"); + /// Console.WriteLine(firstValue.Between(lower, upper)); + /// + /// Console.WriteLine($"{secondValue} between {lower} and {upper}?"); + /// Console.WriteLine(secondValue.Between(lower, upper)); + /// + /// // This will output the following: + /// // 42 between 0 and 20? + /// // False + /// // 15 between 0 and 20? + /// // True + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool Between(this T1 actual, T2 lower, T3 upper) + where T1 : IComparable, IComparable + { + return actual.CompareTo(lower) > 0 && actual.CompareTo(upper) < 0; + } + } +}