Prevent Resharper warning when declaring non-empty sequence return via Contract.Ensures ()?

I use Code Contracts to declare that a property returns a nonempty, nonempty string sequence:

public IEnumerable<string> Filenames { get { Contract.Ensures(Contract.Result<IEnumerable<string>>() != null); // Next line gives Resharper Warning // "Possible null assignment to entity marked with 'not null' attribute": Contract.Ensures(Contract.Result<IEnumerable<string>>().Any()); return new []{"TEST"}; // Dummy data for demo purposes. } } 

I get a warning from Resharper as described in the code comment above.

This is similar to the question here: but I tried to apply the fix in the answer to this question and did not fix this specific problem.

Does anyone know how to fix this (other than using Resharper comments to suppress the warning)?

I am using Resharper 7.1.2 C # Edition, build 7.1.2000.1478

(I tested several machines, and this happens on all of them. Vanilla installation R # - we did not modify any of our XML files, except for me, trying to apply the correction from the answer linked above.)

Additional Information:

I am trying this with Visual Studio 2012 update 2, with .Net 4.0 and .Net 4.5.

In addition, you need to add the CONTRACTS_FULL conditional compilation symbol to the Build project settings (in the "conditional compilation" text box).

+4
source share
1 answer

The problem is that although most Code Contracts are covered in ReSharper ExternalAnnotations, it provides more than one of them (even in any of the custom xmls floating).

I just double-checked ExternalAnnotations from the latest version of ReSharper v8 EAP, and they are still exactly the same as in v7.1.3, so nothing has changed so far.

I will ask a new question, asking if anyone knows how to implement it.

UPDATE: Contracts with code guarantee independent external changes

FINAL: this is not feasible at all - simply because the attribute must somehow be implied for a method containing a code contract, and not for what is inside the code of the code itself ...

+1
source

Source: https://habr.com/ru/post/1481780/


All Articles