Try Microsoft Edge
A fast and secure browser that's designed for Windows 10
Get started
Code Contracts provide a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of preconditions, postconditions, and object invariants. Contracts act as checked documentation of your external and internal APIs. The contracts are used to improve testing via runtime checking, enable static contract verification, and documentation generation.
Code Contracts is now an open source project in GitHub. This page is being kept for historical interest. All downloads, documentation, and discussions take place there.
It is just one of the many projects that are part of the Open Source for Academics program.
Code Contracts bring the advantages of design-by-contract programming to all .NET programming languages. The benefits of writing contracts are:
Improved testability
Static verification We have prototyped numerous static verification tools over the past years. Our current tool takes advantage of contracts to reduce false positives and produce more meaningful errors.
API documentation Our API documentation often lacks useful information. The same contracts used for runtime testing and static verification can also be used to generate better API documentation, such as which parameters need to be non-null, etc.
Our solution consists of using a set of static library methods for writing preconditions, postconditions, and object invariants as well as three tools:ccrewrite, for generating runtime checking from the contracts
The use of a library has the advantage that all .NET languages can immediately take advantage of contracts. There is no need to write a special parser or compiler. Furthermore, the respective language compilers naturally check the contracts for well-formedness (type checking and name resolution) and produce a compiled form of the contracts as MSIL. Authoring contracts in Visual Studio allows programmers to take advantage of the standard intellisense provided by the language services. Previous approaches based on .NET attributes fall far short as they neither provide an expressive enough medium, nor can they take advantage of compile-time checks.
Full details are in the user documentation.
The main people who worked on this project are:
There were also many others, especially interns:
Our tools can be installed in any Visual Studio edition (except Express). The license does allow commercial use. It is available on the Visual Studio Gallery.
After installing please use the link to the documentation under All Programs -> Microsoft Code Contracts to get you started.
If your project uses Code Contracts and would like to have it added to this list, please let us know! Code Contracts is available with a commercial license on the Visual Studio Gallery
Principal Research Software Design Engineer