Possible Duplicates:
Get method name and type using lambda expression
Can I use Expression<Func<T, bool>> and reliably see which properties are referenced in the Func<T, bool>?
Hi,
I want to have a method, which I can use like this
<% Html.TextBoxFor(x=>x.Property, Helper.GetAttributes<ViewModel>(x=>x.PropertyA)) %>
The method header looks like this
public static Dictionary<string, string> GetAttributeValues<T>(Expression<Func<T, object>> myParam)
but how do i find out the name of PropertyA? i need to do some checks before returning the right attributes. thanks in advance..
cheers
PS: thanks to driis post How to get names from expression property? i found the solution
it is
public static Dictionary<string, string> GetAttributeValues<T>(Expression<Func<T, object>> myParam)
{
var item = myParam.Body as UnaryExpression;
var operand = item.Operand as MemberExpression;
Log.Debug(operand.Member.Name);
}