我想关闭代码契约警告,但只针对特定的代码行。我该怎么做?
例如,我得到:
Warning 87 CodeContracts: requires unproven: key != null
为:
return HttpContext.Current.Items[typeof(T).AssemblyQualifiedName];
这在我们的应用程序中永远不会发生。
好吧,一个选择是:
string key = typeof(T).AssemblyQualifiedName; Contract.Assume(key != null); return HttpContext.Current.Items[key];
它有点难看,但我相信它应该管用。