2010-10-28 79 views
2

我想關閉代碼合同警告,但僅限特定的代碼行。我怎麼做?關閉代碼合同警告

舉例來說,我得到:

Warning 87 CodeContracts: requires unproven: key != null 

爲:

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

它永遠不會在我們的應用中發生。

回答

4

好,其中一個方案是:

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

這是一個有點難看,但我相信它應該工作。