nameof(order.User.Age)
return only Age
instead of order.User.Age
What is the reason to do it in more restricted way? If we want only last name we could do something like
public static GetLastName(this string x) {
return string.Split(x, '.').Last();
}
nameof(order.User.Age).GetLastName()
And with one operator we could get both, Age
and order.User.Age
. But with current implementation we can only get Age
. Is there some logic behind this decision? For example, such behavior is necessary for MVC binding
Html.TextBox(nameof(order.User.Age))
order.User
may as well be some function returning an object with propertyName
. What should nameof to in such cases? – Kurtzmannameof
is a compile time constant, so how would it work on an instance? – Embrasure