Code Contracts Ensures for ReSharper ExternalAnnotations

六月ゝ 毕业季﹏ 提交于 2019-12-10 19:01:43

问题


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.

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


回答1:


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")].

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.



来源:https://stackoverflow.com/questions/17257578/code-contracts-ensures-for-resharper-externalannotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!