Beispiel #1
0
 public static object GetBoxed <T>(T value) where T : struct, IComparable, IFormattable, IConvertible
 {
     if (!value.GetType().IsEnum)
     {
         ExceptionUtil.ThrowArgumentException();
     }
     return(BoxingHelper <T> .Get(value));
 }
Beispiel #2
0
 public static T Clamp <T, TComparer>(this TComparer comparer, T value, T min, T max) where TComparer : IComparer <T>
 {
     if (comparer.IsGreaterThan <T, TComparer>(min, max))
     {
         ExceptionUtil.ThrowArgumentException("min", "must be less than or equal to max");
     }
     if (comparer.IsLessThan <T, TComparer>(value, min))
     {
         return(min);
     }
     if (comparer.IsGreaterThan <T, TComparer>(value, max))
     {
         return(max);
     }
     return(value);
 }
Beispiel #3
0
 private static int CompareToThrow <TThis>(object other) where TThis : IComparable <TThis>, IComparable
 {
     ExceptionUtil.ThrowArgumentException($"Invalid type (expected: {typeof(TThis).FullName}, actual: {other.GetType().FullName})", "other");
     return(-1);
 }