DougFinke

Static Checking .NET Code Contracts

or those familiar with Debug. Assert, you may be thinking this is a solved problem. But Debug.Assert only allows you to express that a particular condition should be true at a particular point in the code. Code contracts allow you to declare once that a particular condition should hold any time certain events occur, such as every exit point from a method.

MSDN Magazine Code Contracts

A Precondition Example

After enabling static checking, you can write code and VS 2010 will indicate Code Contract issues with squiggles and tooltips.

Use the project properties Code Contracts tab to enable Squiggles

To get the tab to appear, you need to download the static checker from DevLabs: Code Contracts.

Exit mobile version