0

I have a lambda expression like this (x => x.FirstName) and (x => x.Division.Name) for the definition Expression<Func<Employee,object>>

Now I would like to collect information from this lambda body like the name and type of FirstName and the name and type of Division then Name, how do I do this?

When I browse the value of the expression at debugging I find properties in the expression Body that gives this information, but when I try to call these properties at design time I can't find them!

EDIT

The duplicate question answers my question for (x => x.FirstName) where FirstName is string, however while experimenting I found when (x => x.Age) where Age is integer or bool, the body NoteType becomes Convert and the Body can't get cast to MemberExpression, how should I deal with this situation?

Sisyphus
  • 900
  • 12
  • 32
  • At design time you won't know the derived types but the debugger figures that out for you. – DavidG Oct 20 '17 at 15:27
  • 1
    Sounds like you might benefit from reading/adapting some of the answers from [here](https://stackoverflow.com/q/671968/1364007). – Wai Ha Lee Oct 20 '17 at 15:29
  • The duplicate has multiple 2009 answers, which are relatively hard, because LINQ framework lacked `ExpressionVisitor`. I added [an answer](https://stackoverflow.com/a/46852732/335858) that takes advantage of the new addition, which makes the code embarrassingly straightforward. – Sergey Kalinichenko Oct 20 '17 at 15:50

0 Answers0