Tutorial by Examples

Preconditions allows methods to provide minimum required values for input parameters Example... void DoWork(string input) { Contract.Requires(!string.IsNullOrEmpty(input)); //do work } Static Analysis Result...
Postconditions ensure that the returned results from a method will match the provided definition. This provides the caller with a definition of the expected result. Postconditions may allowed for simplied implmentations as some possible outcomes can be provided by the static analyizer. Example......
Using Code Contracts it is possible to apply a contract to an interface. This is done by declaring an abstract class that implments the interfaces. The interface should be tagged with the ContractClassAttribute and the contract definition (the abstract class) should be tagged with the ContractClas...
While System.Diagnostics.Contracts is included within the .Net Framework. To use Code Contracts you must install the Visual Studio extensions. Under Extensions and Updates search for Code Contracts then install the Code Contracts Tools After the tools are installed you must enable Code Contract...

Page 1 of 1