diff --git a/CSUtilities/Extensions/ObjectExtensions.cs b/CSUtilities/Extensions/ObjectExtensions.cs index 90efe69..b6187cf 100644 --- a/CSUtilities/Extensions/ObjectExtensions.cs +++ b/CSUtilities/Extensions/ObjectExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; namespace CSUtilities.Extensions { @@ -52,5 +53,16 @@ public static void ThrowIf(this T parameter, Check check, string messag throw Activator.CreateInstance(typeof(E), message) as E; } } + + public static void InRange(this T parameter, T min, T max, string message, bool inclusive = true, [CallerMemberName] string name = null) + where T : struct, IComparable + { + int up = parameter.CompareTo(max); + + if (up < 0) + { + throw new ArgumentOutOfRangeException(name, parameter, message); + } + } } }