public static class MemberInfoGetting
{
public static string GetMemberName<T>(System.Linq.Expressions.Expression<System.Func<T>> memberExpression)
{
System.Linq.Expressions.MemberExpression expressionBody = (System.Linq.Expressions.MemberExpression)memberExpression.Body;
return expressionBody.Member.Name;
}
}
object testObj = new object();
string 变量名称 = MemberInfoGetting.GetMemberName(() => testObj);