From de8a237f99494c2b0742b60d3efb51e0596cd5c0 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 17 Jan 2021 12:50:23 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Move=20ComparableExtensions=20to?= =?UTF-8?q?=20child=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Item for #7 and #15 --- X10D/src/ComparableExtensions.cs | 27 ---------- .../ComparableExtensions.cs | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 27 deletions(-) delete mode 100644 X10D/src/ComparableExtensions.cs create mode 100644 X10D/src/ComparableExtensions/ComparableExtensions.cs 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; + } + } +}