我想做这个:
Console.WriteLine( PrintMyName(x => x.EmailAddress) );
public class User{
public string EmailAddress{get;set;}
}
propertyInfo
现在的问题是,如下所示null
。
public string PrintMyName(Func<T,object> member){
var propertyInfo = (member.Body as MemberExpression).Member as PropertyInfo;
return propertyInfo.Name;
}
这样做的正确方法是什么?谢谢