You should do the following:
- Install the Code Contracts add-in as nfechner has noted
- Go to the project properties, ‘Code Contracts’ folder
- Check ‘Perform Runtime Contract Checking’
- Switch ‘Assembly Mode’ to ‘Standard Contract Requires’
- Substitute your
Contract.RequireswithContract.Requires<SomeException>(the first one throwsSystem.Diagnostics.ContractExceptionwhile the second throws the exception you specified which is important for public methods)
That’s the basic setup. For more accurate configuration, refer to the manual
If you use Mono, probably, Contract class is empty. I haven’t done this, but chapter seven from the Contracts manual seems to explain how to provide your own implementation.