jgauffin
jgauffin

Reputation: 101166

Turn off code contracts warning

I want to turn off a code contract warning, but only for specific code lines. How do I do that?

For instance, I get:

Warning 87  CodeContracts: requires unproven: key != null   

for:

return HttpContext.Current.Items[typeof(T).AssemblyQualifiedName];

which will never happen in our applications.

Upvotes: 2

Views: 497

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502216

Well, one option would be:

string key = typeof(T).AssemblyQualifiedName;
Contract.Assume(key != null);
return HttpContext.Current.Items[key];

It's a bit ugly, but I believe it should work.

Upvotes: 4

Related Questions