[英]How to extend predicate in lambda expression parameter
我想在我的方法中擴展表達式參數來添加我自己的過濾器。 我想嘗試做類似下面的事情,但語法錯誤:
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>>
'類型的操作數
首先擴展謂詞會更好,然后反饋為.Where(predicate)
所謂.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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.