我对代码合同和 linq 有疑问。我设法将问题缩小到以下代码示例。现在我被困住了。
public void SomeMethod()
{
var list = new List<Question>();
if (list.Take(5) == null) { }
// resharper hints that condition can never be true
if (list.ForPerson(12) == null) { }
// resharper does not hint that condition can never be true
}
public static IQueryable<Question> ForPerson(this IQueryable<Question> source, int personId)
{
if(source == null) throw new ArgumentNullException();
return from q in source
where q.PersonId == personId
select q;
}
我的 linq 链有什么问题?为什么在分析 ForPerson 调用时不重新分析“抱怨”?
编辑:ForPerson 方法的返回类型从字符串更改为 IQueryable,我的意思是。(我的错)