Parameter validation using Contract
Parameters can be validated by using the Contract class.Example:
private void Foo(object p_obj)
{
System.Diagnostics.Contracts.Contract.Requires(p_obj != null, "Object parameter cannot be null");
}
Note: even though this can be done. It doesn't mean it should.
If a contract requirement fails in production, it's a very bad thing. The resulting exception does not provide useful information as to the cause of the issue.
Last modified by Mohit @ 4/4/2025 8:45:10 AM