Conversation
…lTo()`, `Argument.LessThan()`, and `Argument.LessThanOrEqualTo()`.
|
The technical work looks great, but I wonder if use cases (not already covered by Positive and similar checks) are common enough. |
One real-world example might be String.Substring(int, int). With the new functionality, we would be able to express the boundary conditions like so: public string Substring (int startIndex, int length)
{
Argument.PositiveOrZero(nameof(startIndex), startIndex); // or Argument.GreaterThanOrEqualTo(nameof(startIndex), startIndex, 0);
Argument.LessThan(nameof(startIndex), startIndex, this.Length);
Argument.PositiveOrZero(nameof(length), length); // or Argument.GreaterThanOrEqualTo(nameof(length), length, 0);
Argument.LessThanOrEqualTo(nameof(length), length, this.Length - startIndex);
// Implementation
} |
|
Thanks! Yep I was thinking of something like that or Also just remember one other thought I had when I considered similar methods for v1: E.g Similarly, instead of You could argue the same point about e.g. Positive... methods. |
|
You're right--the proposed exception message might be adequate for constants, but it doesn't meaningfully communicate how to untangle a more dynamic situation (eg " How would you feel about including an overload for these new methods which allows the exception message to be specified? |
Adds the following methods:
Argument.GreaterThan()Argument.GreaterThanOrEqualTo()Argument.LessThan()Argument.LessThanOrEqualTo()