This is not possible in different ways using a simple language, for example. int<5000,20000> .
Although this is possible with a more complex definition, it is not easy. It is hard to define and define all the semantics you want, for example:
- Convert to other types of range
- Convert from built-in numeric types
- What should happen when overflow / underload
- What should the resulting range of types do after arithmetic.
This solution will also not cover cases when you want one range of parameter types to be limited based on a different parameter value.
An alternative would be to use something like Code Contracts to define contracts for your code so that you can execute arbitrary static (compilation time).
Edit: Removed the link to SpecSharp. It looks like it has been replaced by code contracts ...
source share