Parameter validation using Contract
Parameters can be validated by using the Contract class.
Example:
private void Foo(object p_obj) { // do the contract validation here. System.Diagnostics.Contracts.Contract.Requires(p_obj != null,"Object"Parameterparameter'p_obj' cannot be null"); // the rest of the method body would go here. int x = 0; x++; }
Important: Do NOT use this technique for any kind of password or security validation. It can be overridden and bypassed.