人可以让代码分析了解代码契约? [英] Can one make Code Analysis understand Code Contracts?

查看:213
本文介绍了人可以让代码分析了解代码契约?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当结合使用代码分析和代码契约,我得到了很多的警告如

When using Code Analysis and Code Contracts in combination, I get a lot of warnings like

CA1062 :Microsoft.Design:在外部可见的方法Foo.Bar(日志),验证参数使用它之前,登录

CA1062: Microsoft.Design : In externally visible method 'Foo.Bar(Log)', validate parameter 'log' before using it.

在Foo.Bar,我有一个验证日志的合同。

In Foo.Bar, I have a contract that validates log.

public Bar(Log log)
{
   Contract.Requires(log != null);
   log.Lines.Add(...);
   // ...
}



有没有一种方法,使的FxCop理解的代码合同?

Is there a way to make FxCop understand code contracts?

推荐答案

没有,我不认为它在当前的版本可能由合同重写不生成的代码产生的FxCop正在寻找的标准图案。

No I do not think it's possible in the current build as the code generated by the contracts rewriter does not produce the standard pattern that FxCop is looking for.

虽然通常情况下我使用代码合同时,可以禁用这个特殊的FxCop规则。我发现静态验证超过此规则,因为它会嚷嚷有关不检查比的FxCop更积极的损失弥补。我在这里建议同样的办法,这将解决这个问题你。

Typically though I disable this particular FxCop rule when using code contracts. I find the static verifier more than makes up for the loss of this rule as it will yell about a lack of checking much more aggressively than FxCop. I would suggest the same approach here which will fix this problem for you.

这篇关于人可以让代码分析了解代码契约?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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