Understanding Code Contracts

Code Contracts is a new library in the .NET Framework 4.0 offered by the System.Diagnostics.Contract namespace and enables checking, both at runtime and compile time, if the code is respecting specified requirements. This is something that you will often hear about as Contracts by design. The idea is that code needs to respect specified contracts to be considered valid. There are different kinds of contracts, known as preconditions (what the application expects), post-conditions (what the application needs to guarantee), and object invariants (what the application needs to maintain). We cover all of them in next subsections. At the moment it is important to understand some other concepts. Code contracts are a useful ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.