當使用Expression.Call時,方法「Any」使用哪些類型和參數?從表達式調用方法
我有一個內部和外部表達式,我想與任何使用。表達式以編程方式構建。
內(這個工程):
ParameterExpression tankParameter = Expression.Parameter(typeof(Tank), "t");
Expression tankExpression = Expression.Equal(
Expression.Property(tankParameter, "Gun"),
Expression.Constant("Really Big"));
Expression<Func<Tank, bool>> tankFunction =
Expression.Lambda<Func<Tank, bool>>(tankExpression, tankParameter);
外(看起來是正確的):
ParameterExpression vehicleParameter = Expression.Parameter(typeof(Vehicle), "v");
Expression vehicleExpression = Expression.Lambda(
Expression.Property(
vehicleParameter,
typeof(Vehicle).GetProperty("Tank")),
vehicleParameter);
這給了我2個表達式:
v => v.Tank
t => t.Gun == "Really Big";
我在找的是:
v => v.Tank.Any(t => t.Gun == "Really Big");
我正在嘗試使用Expression.Call方法來使用「Any」。 1.這是正確的做法嗎? 2.以下引發異常, 「No method'任何'類型'System.Linq.Queryable'與提供的參數兼容。」
這裏是我正在呼叫的任何:
Expression any = Expression.Call(
typeof(Queryable),
"Any",
new Type[] { tankFunction.Body.Type }, // this should match the delegate...
tankFunction);
如何在任何被調用從vehicleExpression拴tankFunction?