From 2a05cb66707084bc47f3dcb096e3dfa234d489dd Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 17 Jan 2021 13:07:43 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20IComparable=20"operators"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements #22 --- .../ComparableExtensions.cs | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/X10D/src/ComparableExtensions/ComparableExtensions.cs b/X10D/src/ComparableExtensions/ComparableExtensions.cs index d357e9d..bc9cf14 100644 --- a/X10D/src/ComparableExtensions/ComparableExtensions.cs +++ b/X10D/src/ComparableExtensions/ComparableExtensions.cs @@ -50,5 +50,117 @@ namespace X10D.ComparableExtensions { return actual.CompareTo(lower) > 0 && actual.CompareTo(upper) < 0; } + + /// + /// Determines if the current value is greater than another value. + /// + /// The first value. + /// The second value. + /// An type. + /// The comparison operand type. + /// + /// if is greater than + /// -or- + /// otherwise. + /// + /// + /// + /// int first = 5; + /// int second = 10; + /// + /// bool result = first.GreaterThan(second); + /// // result will be False + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool GreaterThan(this T1 value, T2 other) + where T1 : IComparable + { + return value.CompareTo(other) > 0; + } + + /// + /// Determines if the current value is greater than or equal to another value. + /// + /// The first value. + /// The second value. + /// An type. + /// The comparison operand type. + /// + /// if is greater than or equal to + /// -or- + /// otherwise. + /// + /// + /// + /// int first = 5; + /// int second = 10; + /// + /// bool result = first.GreaterThanOrEqualTo(second); + /// // result will be False + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool GreaterThanOrEqualTo(this T1 value, T2 other) + where T1 : IComparable + { + return value.CompareTo(other) >= 0; + } + + /// + /// Determines if the current value is less than another value. + /// + /// The first value. + /// The second value. + /// An type. + /// The comparison operand type. + /// + /// if is less than + /// -or- + /// otherwise. + /// + /// + /// + /// int first = 5; + /// int second = 10; + /// + /// bool result = first.LessThan(second); + /// // result will be True + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool LessThan(this T1 value, T2 other) + where T1 : IComparable + { + return value.CompareTo(other) < 0; + } + + /// + /// Determines if the current value is less than or equal to another value. + /// + /// The first value. + /// The second value. + /// An type. + /// The comparison operand type. + /// + /// if is less than or equal to + /// -or- + /// otherwise. + /// + /// + /// + /// int first = 5; + /// int second = 10; + /// + /// bool result = first.LessThanOrEqualTo(second); + /// // result will be True + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool LessThanOrEqualTo(this T1 value, T2 other) + where T1 : IComparable + { + return value.CompareTo(other) <= 0; + } } }