I\'m trying to write a strongly typed helper which would be something like this:
Html.Lookup(x => x.FooId);
for now I have this:
public static class ExpressionsExtractor
{
public static string Lookup(this HtmlHelper html, Expression> expression)
{
var memberExpression = expression.Body as MemberExpression;
if (memberExpression == null)
return null;
return memberExpression.Member.Name;
}
}
You would then call it with:
var propName = Html.Lookup(x => x.FooId);