3

我想在我的方法中扩展表达式参数以添加我自己的过滤器。我正在尝试执行以下操作,但语法错误:

public static IList<MyPage> DoSomething<T>(Expression<Func<T, bool>> predicate)
{
    return DataStore().GetPages().Where(p => p.PublishDate < DateTime.Now && predicate)
}

编译器抱怨在 Visual Studio 2012 中出现此错误:

错误 29 运算符“&&”不能应用于“ bool”和“ System.Linq.Expressions.Expression<System.Func<T,bool>>”类型的操作数

如果返回 as ,首先扩展谓词会更好然后反馈.Where(predicate)吗?你会怎么做?

4

1 回答 1

4

如果返回为 .Where(predicate),首先扩展谓词会更好吗?你会怎么做?

是的,完全一样,如果我理解你的建议正确的话。您可以.Where()像这样链接:

public static IList<MyPage> DoSomething<T>(Expression<Func<T, bool>> predicate)
{
    return DataStore().GetPages().Where(p => p.PublishDate < DateTime.Now).Where(predicate);
}
于 2013-02-23T09:53:21.053 回答