.Net代码合同-在哪里可以了解更多信息? [英] .Net Code Contracts - Where to learn more?

查看:86
本文介绍了.Net代码合同-在哪里可以了解更多信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我在办公室里听到了有关.Net合同的讨论,但是当我问一些同事时,没有一个人可以轻松地向我解释他们的目的,甚至是什么。

I had overheard some discussion in my office recently about .Net "Contracts" however, when I asked some of my fellow employees, not of them could easily explain to me what they were for, or what they even were.

任何人都没有任何资源,解释和用法教程吗?

Does anyone have any resources, explanations, and perhaps a tutorial on their usage?

谢谢,

Paul

推荐答案

代码契约是.NET 4.0中引入的,它们提供了一种语言不可知的方法来表达程序中的编码假设。

Code Contracts were introduced in .NET 4.0 and they provide a language-agnostic method to express coding assumptions in programs.

基本上,它们使您可以检查前置条件,后置条件和其他功能,并且可以大大改善测试过程和最终编写的代码质量。

They basically allow you to check for pre-conditions, post-conditions and other features and can greatly improve the testing process and the eventual quality of code that is being written.

来自微软:


  • 运行时检查。。我们的二进制重写器通过注入合同来修改程序,这些合同将作为程序执行的一部分进行检查。重写的程序提高了可测试性:每个合同都充当Oracle,为测试运行提供通过/失败指示。自动测试工具(例如Pex)利用合同的优势,通过滤除不满足前提条件的无意义的测试参数来生成更有意义的单元测试。

  • Runtime Checking. Our binary rewriter modifies a program by injecting    the contracts, which are checked as part of program> execution. Rewritten programs improve testability: each contract acts as an oracle, giving a test run a pass/fail indication. Automatic testing tools, such as Pex, take advantage of contracts to generate more meaningful unit tests by filtering out meaningless test arguments that don't satisfy the pre-conditions. 

静态检查。我们的静态检查器甚至可以在不运行程序的情况下,确定是否存在违反合同的情况!它检查隐式合同,例如null取消引用和数组范围以及显式合同。

Static Checking. Our static checker can decide if there are any contract violations without even running the program! It checks for implicit contracts, such as null    dereferences and array bounds, as well as the explicit contracts.

文档生成。。我们的文档生成器使用合同信息扩充了现有的XML文档文件。还有一些新样式表可以与Sandcastle一起使用,以便生成的文档页面具有合同部分。

Documentation Generation. Our documentation generator augments existing XML doc files with contract information. There are also new style sheets that can be used with Sandcastle so that the generated documentation pages have contract sections.

了解详情:

  • Code Contracts | Microsoft Research
  • Code Contracts Overview Video and Tutorial by Greg Young | InfoQ
  • Code Contracts | Microsoft DevLabs
  • Tutorial on Using Code Contracts | jarloo.com

这篇关于.Net代码合同-在哪里可以了解更多信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆