views:

23

answers:

1

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.

+2  A: 

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.

Jon Skeet
`Contract.Assume(typeof(T).AssemblyQualifiedName);` was enough
jgauffin