private static void buildValueGetters(Expression expression, IList <IValueGetter> list)
        {
            var memberExpression = expression as MemberExpression;

            if (memberExpression != null)
            {
                var propertyInfo = (PropertyInfo)memberExpression.Member;
                list.Add(new PropertyValueGetter(propertyInfo));
                if (memberExpression.Expression != null)
                {
                    buildValueGetters(memberExpression.Expression, list);
                }
            }

            //deals with collection indexers, an indexer [0] will look like a get(0) method call expression
            var methodCallExpression = expression as MethodCallExpression;

            if (methodCallExpression != null)
            {
                var methodInfo = methodCallExpression.Method;
                //only supporting constant expressions as means of providing index
                var firstArgumentExpression = methodCallExpression.Arguments.First() as ConstantExpression;
                if (firstArgumentExpression != null)
                {
                    var value             = firstArgumentExpression.Value;
                    var methodValueGetter = new MethodValueGetter(methodInfo, value);
                    list.Add(methodValueGetter);
                }
                if (methodCallExpression.Object != null)
                {
                    buildValueGetters(methodCallExpression.Object, list);
                }
            }
        }
Exemplo n.º 2
0
        private static void buildValueGetters(Expression expression, IList <IValueGetter> list)
        {
            var memberExpression = expression as MemberExpression;

            if (memberExpression != null)
            {
                var propertyInfo = (PropertyInfo)memberExpression.Member;
                list.Add(new PropertyValueGetter(propertyInfo));
                if (memberExpression.Expression != null)
                {
                    buildValueGetters(memberExpression.Expression, list);
                }
            }

            //deals with collection indexers, an indexer [0] will look like a get(0) method call expression
            var methodCallExpression = expression as MethodCallExpression;

            if (methodCallExpression != null)
            {
                var        methodInfo = methodCallExpression.Method;
                Expression argument   = methodCallExpression.Arguments.First();

                object value;
                if (TryEvaluateExpression(argument, out value))
                {
                    var methodValueGetter = new MethodValueGetter(methodInfo, value);
                    list.Add(methodValueGetter);
                }

                if (methodCallExpression.Object != null)
                {
                    buildValueGetters(methodCallExpression.Object, list);
                }
            }
        }
 public bool Equals(MethodValueGetter other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other._methodInfo, _methodInfo) && Enumerable.SequenceEqual(other._arguments, _arguments));
 }
Exemplo n.º 4
0
 public bool Equals(MethodValueGetter other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other._methodInfo, _methodInfo) && Equals(other._firstArgument, _firstArgument));
 }
Exemplo n.º 5
0
 public SingleMethod(MethodValueGetter getter, Type ownerType)
 {
     _getter    = getter;
     _ownerType = ownerType;
 }
Exemplo n.º 6
0
 public SingleMethod(MethodValueGetter getter)
 {
     _getter = getter;
 }
Exemplo n.º 7
0
        private static void buildValueGetters(Expression expression, IList <IValueGetter> list)
        {
            var memberExpression = expression as MemberExpression;

            if (memberExpression == null && expression is UnaryExpression)
            {
                memberExpression = ((UnaryExpression)expression).Operand as MemberExpression;
            }

            if (memberExpression != null)
            {
                var propertyInfo = (PropertyInfo)memberExpression.Member;
                list.Add(new PropertyValueGetter(propertyInfo));
                if (memberExpression.Expression != null)
                {
                    buildValueGetters(memberExpression.Expression, list);
                }
            }

            //deals with collection indexers, an indexer [0] will look like a get(0) method call expression
            var methodCallExpression = expression as MethodCallExpression;

            if (methodCallExpression != null)
            {
                var        methodInfo = methodCallExpression.Method;
                Expression argument   = methodCallExpression.Arguments.FirstOrDefault();

                if (argument == null)
                {
                    var methodValueGetter = new MethodValueGetter(methodInfo, new object[0]);
                    list.Add(methodValueGetter);
                }
                else
                {
                    object value;
                    if (TryEvaluateExpression(argument, out value))
                    {
                        var methodValueGetter = new MethodValueGetter(methodInfo, new object[] { value });
                        list.Add(methodValueGetter);
                    }
                }



                if (methodCallExpression.Object != null)
                {
                    buildValueGetters(methodCallExpression.Object, list);
                }
            }

            if (expression.NodeType == ExpressionType.ArrayIndex)
            {
                var binaryExpression = (BinaryExpression)expression;

                var indexExpression = binaryExpression.Right;

                object index;
                if (TryEvaluateExpression(indexExpression, out index))
                {
                    var indexValueGetter = new IndexerValueGetter(binaryExpression.Left.Type, (int)index);

                    list.Add(indexValueGetter);
                }

                buildValueGetters(binaryExpression.Left, list);
            }
        }
Exemplo n.º 8
0
 public bool Equals(MethodValueGetter other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other._methodInfo, _methodInfo) && Equals(other._firstArgument, _firstArgument);
 }
Exemplo n.º 9
0
 public bool Equals(MethodValueGetter other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other._methodInfo, _methodInfo) && Enumerable.SequenceEqual(other._arguments, _arguments);
 }