Contract.Assert不引发编译错误 [英] Contract.Assert do not throw compilation error

查看:39
本文介绍了Contract.Assert不引发编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在使用Contract的编译时为我的类型添加验证,但不幸的是,它不起作用。例如,下面的代码在编译项目时不会给编译器错误。我应该启用某些功能吗?

I am trying to add validation for my type at compilation time using Contract but unfortunately it do not work. For example code below do not give compiler error while compiling project. Should I enable something?

Contract.Assert(false, "Invalid state!");


推荐答案

是的,您需要启用静态检查。进入项目属性,然后访问代码合同选项卡。当然,您需要首先安装static checker扩展程序,该IIRC仅可用于Visual Studio Ultimate。有关详细信息,请参见用户文档。确切的选项。

Yes, you need to enable the static checking. Go into the project properties and visit the "Code Contracts" tab. Of course you'll need to have installed the static checker extension first, which IIRC is only available for Visual Studio Ultimate. See the user documentation for details of the exact options available.

请注意,这发生在初始编译阶段之后,因此有时您会看到构建和静态检查器的结果。 (这不是真正的编译器错误,而是合同检查错误。)

Note that this happens after the initial compilation phase, so sometimes you'll see a delay between the first part of the build and the results of the static checker. (It's not really a "compiler" error - it's a "contract checking" error.)

这篇关于Contract.Assert不引发编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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