-
Hi, pure technical question (no critic, offense...) What is the reason for explicit implementing e.g. OutOfRange for primitive types? I have tested this and it's working well: public static T OutOfRange<T>(this IGuardClause guardClause, T input, string parameterName, T rangeFrom, T rangeTo, string? message = null)
where T: IComparable, IComparable<T>
{
if (rangeFrom.CompareTo(rangeTo) > 0)
{
throw new ArgumentException(message ?? $"{nameof(rangeFrom)} should be less or equal than {nameof(rangeTo)}");
}
if (input.CompareTo(rangeFrom) < 0 || input.CompareTo(rangeTo) > 0)
{
if (string.IsNullOrEmpty(message))
{
throw new ArgumentOutOfRangeException(parameterName, $"Input {parameterName} was out of range");
}
throw new ArgumentOutOfRangeException(message, (Exception?)null);
}
return input;
} tia |
Beta Was this translation helpful? Give feedback.
Answered by
ardalis
Sep 30, 2021
Replies: 1 comment 1 reply
-
I think nobody thought to apply generics to it until now. I'd be happy to add this. Want to make a PR? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ardalis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think nobody thought to apply generics to it until now. I'd be happy to add this. Want to make a PR?