As far as I read in a nutshell book, code contracts could degrade the runtime performance.
Is it possible to disable code contracts in production?
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.
NET 4.0. Code Contracts API includes classes for static and runtime checks of code and allows you to define preconditions, postconditions, and invariants within a method.
Design By Contract (DbC) is a software correctness methodology. It uses preconditions and postconditions to document (or programmatically assert) the change in state caused by a piece of a program. Design by Contract is a trademarked term of BertrandMeyer and implemented in his EiffelLanguage as assertions.
The user manual explains this in a fair amount of detail - there are all kinds of options you can have. Each build configuration can have different settings for which contracts are checked at execution time, and it's not an "all or nothing" choice - you can enforce all, some or none of the contracts, based on settings which can be tweaked in Visual Studio.
I have my favorite options described on my blog.
To summarize:
Some people prefer Preconditions to be included in their Release build. This is particularly useful if distributing via NuGet because they don't support Code Contract dlls. For my NuGet packages, I'm migrating towards including Preconditions in the Release builds, but also having a separate download for a "Release without Preconditions" build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With