public static T NotOutOfRange <T>(this IEnsureArgument ensureArgument, IComparable <T> value, string paramName, IComparable <T> lowerBound = null, IComparable <T> upperBound = null) { return(ensureArgument.NotOutOfRange(value, paramName, DefaultMessage(), lowerBound, upperBound)); // Generate a default message to use for the exception, incorporating the boundary parameters. string DefaultMessage() { var message = "Value cannot be"; if (lowerBound is not null) { message += $" less than {lowerBound}"; } if (upperBound is not null) { if (lowerBound is not null) { message += " or"; } message += $" greater than {upperBound}"; } message += "."; return(message); } }
public static TEnum NotOutOfRange <TEnum>(this IEnsureArgument ensureArgument, Expression <Func <TEnum> > argument) where TEnum : struct, Enum { return(ensureArgument.NotOutOfRange(argument.GetValue(), argument.GetName())); }
public static T NotOutOfRange <T>(this IEnsureArgument ensureArgument, Expression <Func <IComparable <T> > > argument, string message, IComparable <T> lowerBound = null, IComparable <T> upperBound = null) { return(ensureArgument.NotOutOfRange(argument.GetValue(), argument.GetName(), message, lowerBound, upperBound)); }