From e2e7b3a94756b98bc175de5871b710759643dd17 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 27 Jun 2021 13:15:21 +0100 Subject: [PATCH] (#42) Validate not-null values --- .../ComparableExtensions.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/X10D/src/ComparableExtensions/ComparableExtensions.cs b/X10D/src/ComparableExtensions/ComparableExtensions.cs index dd7615e..5454a87 100644 --- a/X10D/src/ComparableExtensions/ComparableExtensions.cs +++ b/X10D/src/ComparableExtensions/ComparableExtensions.cs @@ -125,6 +125,11 @@ namespace X10D public static bool GreaterThan(this T1 value, T2 other) where T1 : IComparable { + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } + return value.CompareTo(other) > 0; } @@ -152,6 +157,11 @@ namespace X10D public static bool GreaterThanOrEqualTo(this T1 value, T2 other) where T1 : IComparable { + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } + return value.CompareTo(other) >= 0; } @@ -179,6 +189,11 @@ namespace X10D public static bool LessThan(this T1 value, T2 other) where T1 : IComparable { + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } + return value.CompareTo(other) < 0; } @@ -206,6 +221,11 @@ namespace X10D public static bool LessThanOrEqualTo(this T1 value, T2 other) where T1 : IComparable { + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } + return value.CompareTo(other) <= 0; } @@ -232,6 +252,11 @@ namespace X10D public static T Max(this T value, T other) where T : IComparable { + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } + return value.GreaterThan(other) ? value : other; } @@ -258,6 +283,11 @@ namespace X10D public static T Min(this T value, T other) where T : IComparable { + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } + return value.LessThan(other) ? value : other; } }