开发者

Get property name from it's value

How does Microsoft MVC 开发者_开发知识库know that the name of the property is "Phone" since we have only the object instance and one of it's properties' value?

<%: Html.TextBoxFor(x => x.Phone) %>


You haven't got the property's value - you've got an expression tree which tells you how to obtain the value from an item. That expression tree can be analyzed by the framework to find the property name.

Now if it were

<%: Html.TextBoxFor(x.Phone) %>

then that would genuinely be just getting the value... but the lambda expression is being converted into an expression tree by the C# compiler.


They are using this 'trick'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜