Skip to content

Commit

Permalink
inrange fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Nov 18, 2024
1 parent cddd1b0 commit 61b92aa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions CSUtilities/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;

namespace CSUtilities.Extensions
{
Expand Down Expand Up @@ -53,15 +54,14 @@ public static void ThrowIf<T, E>(this T parameter, Check<T> check, string messag
}
}

public static void InRange<T, E>(this T parameter, T min, T max, string message, bool inclusive = true)
public static void InRange<T>(this T parameter, T min, T max, string message, bool inclusive = true, [CallerMemberName] string name = null)
where T : struct, IComparable<T>
where E : Exception, new()
{
int up = parameter.CompareTo(max);

if (up < 0)
{
throw Activator.CreateInstance(typeof(E), message) as E;
throw new ArgumentOutOfRangeException(name, parameter, message);
}
}
}
Expand Down

0 comments on commit 61b92aa

Please sign in to comment.