をパラメーターとして受け入れるメソッドがExpression<Func<T, bool>>
あります。List.Find() メソッドの述語として使用したいのですが、List が取る述語に変換できないようです。これを行う簡単な方法を知っていますか?
public IList<T> Find<T>(Expression<Func<T, bool>> expression) where T : class, new()
{
var list = GetList<T>();
var predicate = [what goes here to convert expression?];
return list.Find(predicate);
}
アップデート
tvanfosson と 280Z28 からの回答を組み合わせて、これを使用しています。
public IList<T> Find<T>(Expression<Func<T, bool>> expression) where T : class, new()
{
var list = GetList<T>();
return list.Where(expression.Compile()).ToList();
}