(#42) Validate not-null values

This commit is contained in:
Oliver Booth 2021-06-27 13:15:21 +01:00
parent d6f4a96257
commit e2e7b3a947
1 changed files with 30 additions and 0 deletions

View File

@ -125,6 +125,11 @@ namespace X10D
public static bool GreaterThan<T1, T2>(this T1 value, T2 other) public static bool GreaterThan<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2> where T1 : IComparable<T2>
{ {
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
return value.CompareTo(other) > 0; return value.CompareTo(other) > 0;
} }
@ -152,6 +157,11 @@ namespace X10D
public static bool GreaterThanOrEqualTo<T1, T2>(this T1 value, T2 other) public static bool GreaterThanOrEqualTo<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2> where T1 : IComparable<T2>
{ {
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
return value.CompareTo(other) >= 0; return value.CompareTo(other) >= 0;
} }
@ -179,6 +189,11 @@ namespace X10D
public static bool LessThan<T1, T2>(this T1 value, T2 other) public static bool LessThan<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2> where T1 : IComparable<T2>
{ {
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
return value.CompareTo(other) < 0; return value.CompareTo(other) < 0;
} }
@ -206,6 +221,11 @@ namespace X10D
public static bool LessThanOrEqualTo<T1, T2>(this T1 value, T2 other) public static bool LessThanOrEqualTo<T1, T2>(this T1 value, T2 other)
where T1 : IComparable<T2> where T1 : IComparable<T2>
{ {
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
return value.CompareTo(other) <= 0; return value.CompareTo(other) <= 0;
} }
@ -232,6 +252,11 @@ namespace X10D
public static T Max<T>(this T value, T other) public static T Max<T>(this T value, T other)
where T : IComparable<T> where T : IComparable<T>
{ {
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
return value.GreaterThan(other) ? value : other; return value.GreaterThan(other) ? value : other;
} }
@ -258,6 +283,11 @@ namespace X10D
public static T Min<T>(this T value, T other) public static T Min<T>(this T value, T other)
where T : IComparable<T> where T : IComparable<T>
{ {
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
return value.LessThan(other) ? value : other; return value.LessThan(other) ? value : other;
} }
} }