Jon,
I'm not an expert on Delphi, but my impression is that the OP wanted
something more. Yes, the range class does work, but that's not the
point.
With context bound objects, you can do something like:
public void MyFunction([Range(0, 5)] int value)
{
// Do something with value here.
// NO need to check against range, since it will have
// already been checked by the context bound object.
}
This is a ficticuous context bound attribute, used to display the
point.
This way, his function can assume the check passed, otherwise, the
interception code which the Range attribute handles would throw an
exception.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Jon Skeet said:
Generics doesn't really do much here (yes, compile time checking
against
the type passed in is nice)
It also prevents boxing.
but I think that the thing the OP is trying to
get at is that he doesn't want to perform a check manually, he wants
to
say
somehow that this is his range, and have the runtime enforce it.
Well, I'm not sure I see much difference between:
ColorRange = White..Blue;
and
Range<Color> colorRange = new Range<Color>(Color.White, Color.Blue);
(I'd have expected new Range(Color.White, Color.Blue) to work, but it
doesn't - I need to check the spec to see why.)
The former is certainly neater, but you still get to find out
inclusivity etc - and it probably wouldn't be too hard to give it a bit
more functionality if required.
Maybe I'm missing some more functionality - but all the examples given
can be done with the Range type I gave.