public static object GetBoxed <T>(T value) where T : struct, IComparable, IFormattable, IConvertible { if (!value.GetType().IsEnum) { ExceptionUtil.ThrowArgumentException(); } return(BoxingHelper <T> .Get(value)); }
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); }
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); }