I have the following:
Expression<Func<Car, int>> myExpr = car => car.Wheel.Tyre.Pressure;
I want to remove the parameter, and make the first member the parameter for a sub-expression, so i end up with:
Expression<Func<Wheel, int>> mySubExpr = wheel => wheel.Tyre.Pressure;
This needs to work for any expression tree of the above format, including MemberExpression
, MethodCallExpression
and any other Expression
which has a .Expression
property. For example:
Expression<Func<Car, int>> myOtherExpr = car => car.GetRearLeftWheel().GetTyre().Pressure
or
Expression<Func<Car, int>> anotherExpr = car => car.Wheel.GetTyre().GetPressure();
How would I achieve this elegantly?
Thanks
Andrew