Wie erstelle ich einen Ausdrucksbaum, der IEnumerable <TSource> .Any (…) aufruft?
Ich versuche, einen Ausdrucksbaum zu erstellen, der Folgendes darstellt:
myObject.childObjectCollection.Any(i => i.Name == "name");
us Gründen der Übersichtlichkeit habe ich folgende Angabe
//'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 Expression.Call(propertyExp, method, predicateExp);
}
Was mache ich falsch? Hat jemand Vorschläge?