コード例 #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));
 }