Here is my problem. I am a very big fan of Design by contract, I am using this concept especially when developing libraries that can be used by other developers. I just found out a new way of doing this which is: Contract.Requires
instead of Exception
:
So instead of having:
public void SomeMethod(string name){
if(name==null) throw new NullArgumentException("Null values not supported");
}
I now have:
public void SomeMethod(string name){
Contract.Requires(name != null);
}
EDIT: I am working under VS2010 on debug mode.
Problem: Contract.Requires
does not do anything, even when name
is null
!
The MSDN documentation says:
Specifies a precondition contract for the enclosing method or property.
But nothing is specified in case the condition is not met!
I also noticed there are other Contract.Requires
overloads that throw exception, display message... but then what is Contract.Requires(Boolean)
for?
EDIT Answer below highlighted that a plug-in must be installed to have the full power of Contract
API but then what about Mono users who want their code to behave the same on different platforms?