我正在尝试创建一个表示以下内容的表达式树:
myObject.childObjectCollection.Any(i => i.Name == "name");
Run Code Online (Sandbox Code Playgroud)
为清楚起见,我有以下内容:
//'myObject.childObjectCollection' is represented here by 'propertyExp'
//'i => i.Name == "name"' is represented here by 'predicateExp'
//but I am struggling with the Any() method reference - if I make the parent method
//non-generic Expression.Call() fails but, as per below, if i use <T> the
//MethodInfo object is always null - I can't get a reference to it
private static MethodCallExpression GetAnyExpression<T>(MemberExpression propertyExp, Expression predicateExp)
{
MethodInfo method = typeof(Enumerable).GetMethod("Any", new[]{ typeof(Func<IEnumerable<T>, Boolean>)});
return …Run Code Online (Sandbox Code Playgroud)