【.Net码农】如何获取类中属性的名称

http://bbs.csdn.net/topics/390095336


public static string GetPropertyName(Expression> expr)
        {
            var rtn = "";
            if (expr.Body is UnaryExpression)
            {
                rtn = ((MemberExpression)((UnaryExpression)expr.Body).Operand).Member.Name;
            }
            else if (expr.Body is MemberExpression)
            {
                rtn = ((MemberExpression)expr.Body).Member.Name;
            }
            return rtn;
        }





你可能感兴趣的:(.Net码农)