P
Peter Kenyon
Hi,
I see that it's possible to apply attributes to function parameters.
Wouldn't it be great if the compilers could use these to generate
borderplate code, such as parameter checking.
Eg instead of typing
void MyFunction(string param1, int param2)
{
if(param1 == null)
throw new ArgumentNullException("param1");
if(param2 < 0)
throw new ArgumentOutOfBoundsException("param2");
if(param2 > 99)
throw new ArgumentOutOfBoundsException("param2");
// ......
}
you could simply type:
void MyFunction([NotNull] string param1, [Min(0), Max(99)] int param2)
{
// ......
}
Not only would this save a lot of time, it would also be less error-prone
(no chance of leaving out a validation check) and more self-documenting.
Just my 2 cents worth
Peter
I see that it's possible to apply attributes to function parameters.
Wouldn't it be great if the compilers could use these to generate
borderplate code, such as parameter checking.
Eg instead of typing
void MyFunction(string param1, int param2)
{
if(param1 == null)
throw new ArgumentNullException("param1");
if(param2 < 0)
throw new ArgumentOutOfBoundsException("param2");
if(param2 > 99)
throw new ArgumentOutOfBoundsException("param2");
// ......
}
you could simply type:
void MyFunction([NotNull] string param1, [Min(0), Max(99)] int param2)
{
// ......
}
Not only would this save a lot of time, it would also be less error-prone
(no chance of leaving out a validation check) and more self-documenting.
Just my 2 cents worth
Peter