我有以下内容:
Expression<Func<Car, int>> myExpr = car => car.Wheel.Tyre.Pressure;
我想删除参数,并使第一个成员成为子表达式的参数,所以我最终得到:
Expression<Func<Wheel, int>> mySubExpr = wheel => wheel.Tyre.Pressure;
这需要适用于上述格式的任何表达式树,包括MemberExpression
,MethodCallExpression
以及任何其他Expression
具有.Expression
属性的表达式树。例如:
Expression<Func<Car, int>> myOtherExpr = car => car.GetRearLeftWheel().GetTyre().Pressure
或者
Expression<Func<Car, int>> anotherExpr = car => car.Wheel.GetTyre().GetPressure();
我将如何优雅地实现这一目标?
谢谢
安德鲁