【发布时间】:2014-08-27 15:58:45
【问题描述】:
我有一个成员 Predicate 的班级,我想在 Linq 表达式中使用它:
using System.Linq;
class MyClass
{
public bool DoAllHaveSomeProperty()
{
return m_instrumentList.All(m_filterExpression);
}
private IEnumerable<Instrument> m_instrumentList;
private Predicate<Instrument> m_filterExpression;
}
当我读到“Predicate<T> [...] 完全等同于 Func<T, bool>”(see here)时,我希望这会起作用,因为 All 接受为参数:Func<Instrument, bool> predicate。
但是,我得到了错误:
Argument 2: cannot convert from 'System.Predicate<MyNamespace.Instrument>' to 'System.Type'
有没有办法将谓词转换为该函数将吞下的参数?
【问题讨论】: