In this blog post I am presenting a simple validation framework that you can reuse in your code. Also I will be putting here two code snippets that will make it easier for you to add preconditions to your code.
When Visual Studio 2010 was first realeased, one of the features that I expected the most was code contracts. Unfortunately after including them in one of my large projects, it became more clear that at this moment it is not mature enough to be used. Build time increases rapidly when having a lot of source code files and using the code contracts. Enabling static contract validation is even worse, almost doubling the build time on an average development machine.
All that being said, I really like the code contracts way of specifying preconditions. Most of the time I don’t use post-conditions, but being able to specify validation criteria means that the code will be more robust.