【发布时间】:2010-06-19 10:09:06
【问题描述】:
我对代码合同和 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 调用时,为什么 resharper 不“抱怨”?
EDIT:ForPerson 方法的返回类型从字符串更改为 IQueryable,我的意思是。 (我的坏)
【问题讨论】:
标签: linq resharper code-contracts