示例#1
0
        // PRIVATE METHODS //////////////////////////////////////////////////
        #region Methods
        private static string GetMemberName(Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var memberExpression = expression as MemberExpression;

            if (memberExpression != null)
            {
                // Reference type property or field
                return(memberExpression.Member.Name);
            }

            var methodCallExpression = expression as MethodCallExpression;

            if (methodCallExpression != null)
            {
                // Reference type method
                return(methodCallExpression.Method.Name);
            }

            var unaryExpression = expression as UnaryExpression;

            if (unaryExpression != null)
            {
                // Property, field of method returning value type
                return(StaticReflection.GetMemberName(unaryExpression));
            }

            throw new ArgumentException(
                      "Invalid expression, must be either a MemberExpression, MethodCallExpression, or UnaryExpression.");
        }
示例#2
0
        public static string GetMemberName <T>(Expression <Action <T> > expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(StaticReflection.GetMemberName(expression.Body));
        }
示例#3
0
 public static string GetMemberName <T>(this T instance, Expression <Action <T> > expression)
 {
     return(StaticReflection.GetMemberName(expression));
 }
示例#4
0
 public static string GetMemberName <T, TProperty>(this T instance, Expression <Func <T, TProperty> > expression)
 {
     return(StaticReflection.GetMemberName(expression));
 }