问题
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