.NET 4 Code Contracts: “requires unproven: source != null”

╄→尐↘猪︶ㄣ 提交于 2019-12-05 10:10:21
dc42

My guess is that one of the methods CreateSet, OfType and AsEnumerable is declared as an extension method with a this-parameter called "source", and CodeContrcts can't prove it is not null. Also, don't you need to add a Requires clause to specify that _uow is non-null on entry?

CreateSet appears to be the extension method since it doesn't appear in MSDN. If the method should never return null, you can enforce this by adding this contract to CreateSet:

Contract.Ensures(Contract.Result<T>() != null);

When the CodeContracts analyzer sees this rule, it will take it as proof that the input to OfType will not be null, and the warning should go away.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!