I previously saw a thread on StackOverflow that had some discussion on this, however I am unable to find it again!
I am interested to know if the System.Diagnostics.Contract classes should be used in 'real code', ie a release build of production code? I ask this, because based on the namespace description it appears the Contract is intended to debugging, or analysis purposes.
It seems like a useful library where pre/post conditions for functionality is important, and may avoid some of the effort in writing lots of if/then/else checks, so if this is the case, is there an alternative in the core libraries?
Section 5.1 (Argument Validation and Contracts) of the documentation details the three main usage modes you might consider for using Contracts:
So there is at least one usage mode where you'd use Contracts in Release builds, at least as the official documentation is concerned.
Quote:
This also hints at what the alternative using only the other parts of the framework would be: The usual way using if-then-throw.