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 fd729a9 commit 8e90ba9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions CSUtilities/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ public static void ThrowIf<T, E>(this T parameter, Check<T> check, string messag
}
}

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

if (up < 0)
if (value.CompareTo(max) >= 1 && value.CompareTo(min) <= -1)
{
throw new ArgumentOutOfRangeException(name, parameter, message);
throw new ArgumentOutOfRangeException(name, value, message);
}
}
}
Expand Down

0 comments on commit 8e90ba9

Please sign in to comment.