Convert a lambda to a dotted string e.g. x => x.Address.City becomes Address.City
I want to convert a lambda expression referencing a property or sub-property of an o开发者_JS百科bject, e.g. x => x.Address.City
into a string Address.City
. Is there an existing framework method (MVC, EF, ...?) that does this or do I need to roll my own? If the latter, any code out there already that does this?
Yes, MVC has this ability built in. It's used in the HTML Helpers, which can take an expression and render an <input name = "Address.City">
. Look in ExpressionHelper.cs in the MVC source code.
精彩评论