Parameter Validation
Parameter Validation is achieved through the use of ParameterValidationManager.
To wire up parameter validation you need to do the following
-
Create a pointer to the method.
This is done by creating a static instance of a System.RuntimeMethodHandle.
This pointer is required to avoid the performance hit associated with determining a method from its name (as a string).
-
Add Rules to some parameters.
This can be is done through attributes, runtime code, or xml configuration.
For the purposes of this example we will stick to attributes.
-
Call
ParameterValidationManager.ThrowException
in the first line of your method.
This will check that the Rules are valid and throw an System.ArgumentException
for the first invalid argument.
The result will look something like this
For full details of ParameterValidationManager features
have a look at its various methods.