Code Contracts for .NET
Posted: (EET/GMT+2)
Microsoft's DevLabs on MSDN has just recently released a new set of tools for .NET developers: Code Contracts. According to the documentation, Code Contracts "provide[s] a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of pre-conditions, post-conditions, and object invariants." Sounds good!
Code Contracts allows you to access a new namespace called System.Diagnostics.Contracts, and allows you to write Debug.Assert-like statements to check pre and post conditions in your code. However, the idea differs from Debug.Assert in that it is mostly for internal state/condition checks. On the other hand, Code Contracts allows you to use Visual Studio 2008 Team System to specify human or machine understandable conditions (more about this in the FAQ). To learn more, Code Contract's user manual is available here.
Note that this Code Contracts is a side-result of Microsoft research project called Spec#. Check it out as well.