In fact, this is an expression tree move that you pass to the helper method to get the property names. In practice, it looks something like this:
MemberExpression memberExpression = (MemberExpression) expression.Body; propertyName = memberExpression.Member.Name;
Of course, this is not complete - for example, you will need to approach the expression chain when there are several property calls in the passed expression, you will have to consider other types of expressions that are passed than MemberExpression, etc., but you get this idea . Remember that an expression is a code expression that is represented as data. Also, since MVC is open source, you can find the exact code that they use to get the html name in the sources if you want.
To answer the second question, the answer is no. Passing βonly propertiesβ without a lambda (which will be Expression<Func<T,object>> ) will not work, because then the function can only see the passed value - and nothing about how the call code arrived with this value.
driis source share