Skip to content

Commit

Permalink
Merge pull request #10 from DomCR/object-extensions
Browse files Browse the repository at this point in the history
object ext
  • Loading branch information
DomCR authored Nov 18, 2024
2 parents 041deaf + 61b92aa commit fd729a9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 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 @@ -52,5 +53,16 @@ public static void ThrowIf<T, E>(this T parameter, Check<T> check, string messag
throw Activator.CreateInstance(typeof(E), message) as E;
}
}

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>
{
int up = parameter.CompareTo(max);

if (up < 0)
{
throw new ArgumentOutOfRangeException(name, parameter, message);
}
}
}
}

0 comments on commit fd729a9

Please sign in to comment.