Ejemplo n.º 1
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            var method   = node.Method;
            var property = PropertyInfoEx.Property(method);

            if (property == null)
            {
                return(base.VisitMethodCall(node));
            }
            // rewrite...
            var instance = Visit(node.Object);
            var isSet    = ReferenceEquals(property.SetMethod, method);

            if (!isSet)
            {
                if (node.Arguments.Count == 0)
                {
                    return(instance.Property(property));
                }
                return(instance.Property(property, node.Arguments.Select(Visit)));
            }
            // set method =\
            // last argument is value, other - index
            if (node.Arguments.Count == 1)
            {
                return(instance.Property(property).Assign(Visit(node.Arguments[0])));
            }
            return(instance.Property(property, node.Arguments.Take(node.Arguments.Count - 1).Select(Visit))
                   .Assign(node.Arguments[node.Arguments.Count - 1]));
        }
Ejemplo n.º 2
0
        public void PropertyFromMethodWorks()
        {
            var prop   = typeof(MultiIndexed).Property("Item", typeof(int));
            var method = prop.GetGetMethod();

            Assert.Equal(prop, PropertyInfoEx.Property(method));
            Assert.Null(PropertyInfoEx.Property(typeof(PropertyInfoExTests).GetTypeInfo().GetMethod("PropertyFromMethodWorks")));
        }