.net 4.0 Code Contracts. When to use? When are they a waste of time?

后端 未结 3 1274
感情败类
感情败类 2020-12-31 17:17

I have been studying .NET 4.0 Code Contracts and looking on stackoverflow as well at question regarding this.

I still have never come across any sample code that use

3条回答
  •  北海茫月
    2020-12-31 17:29

    One of the primary reasons to use CodeContracts is to enable Static Analysis to detect violations of the CodeContracts so they're caught early rather than resulting in bugs or unknown behavior at runtime.

    You can disable runtime enforcement of CodeContracts if you want to.

    Another good reason to use them is to add Contract definitions to XML Code Comments to enhance API documentation. This also works with Sandcastle though there are some tweaks necessary to integrate them fully. Refer to section 8.3 in the Code Contracts User Manual dated 2/4/2011 (or later) available at http://research.microsoft.com/en-us/projects/contracts/userdoc.pdf

提交回复
热议问题