From d6f4a96257f01e11fbec61eb1eab3d073f453d93 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 27 Jun 2021 13:14:42 +0100 Subject: [PATCH] (#42) Validate lower <= upper --- X10D/src/ComparableExtensions/ComparableExtensions.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/X10D/src/ComparableExtensions/ComparableExtensions.cs b/X10D/src/ComparableExtensions/ComparableExtensions.cs index a38de3b..dd7615e 100644 --- a/X10D/src/ComparableExtensions/ComparableExtensions.cs +++ b/X10D/src/ComparableExtensions/ComparableExtensions.cs @@ -45,12 +45,21 @@ namespace X10D /// public static bool Between(this T1 value, T2 lower, T3 upper) where T1 : IComparable, IComparable + where T2 : IComparable + where T3 : IComparable { if (value is null) { throw new ArgumentNullException(nameof(value)); } + if (lower.GreaterThan(upper)) + { + throw new ArgumentException( + string.Format(ExceptionMessages.LowerCannotBeGreaterThanUpper, lower, upper), + nameof(lower)); + } + return value.CompareTo(lower) > 0 && value.CompareTo(upper) < 0; }