代码契约确保ReSharper的ExternalAnnotations [英] Code Contracts Ensures for ReSharper ExternalAnnotations

查看:180
本文介绍了代码契约确保ReSharper的ExternalAnnotations的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何添加代码契约保证了ReSharper的ExternalAnnotations?它的不存在,在过去V7.1.3也不在最新的V8 EAP,并且没有任何自定义XML的漂浮的。

Does anyone know how to add Code Contracts Ensures in ReSharper ExternalAnnotations? It's not there in the last v7.1.3 nor in the latest v8 EAP, and neither in any of the custom xmls floating around.

具体应该检测一个方法确实不可以返回一个空: Contract.Ensures(!Contract.Result< T>()= NULL);

Specifically it should detect if a method does not return a null: Contract.Ensures(Contract.Result<T>() != null);

推荐答案

如果您正在试图安抚简单的分析引擎,用最简单的事情是 [NOTNULL] 在方法声明的前面。合同注释到您发布上面的链接是定义输入参数和返回值之间的关系更强大的机制如 [ContactAnnotation(空=>空)]

If you're attempting to simply appease the analysis engine, the simplest thing to use is [NotNull] in front of the method declaration. The Contract Annotations to which you posted a link above is a more powerful mechanism for defining relationships between input parameters and the return value, e.g., [ContactAnnotation("null => null")].

然而,分析明确了 Contract.Ensures 语句是一个完全不同的命题,因为没有自动分析可以为这个说法通过 [ContractAnnotation] 或任何其他ReSharper的标注属性。

However, explicitly analyzing for a Contract.Ensures statement is an entirely different proposition, as no automatic analysis can be defined for this statement via [ContractAnnotation] or any other ReSharper annotation attribute.

这篇关于代码契约确保ReSharper的ExternalAnnotations的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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