Exemplo n.º 1
0
        protected override Expression VisitMember(MemberExpression e)
        {
            var isMember         = e.Expression != null && e.Expression.NodeType == ExpressionType.Parameter;
            var isNullableMember = e.Expression != null && e.Expression.NodeType == ExpressionType.MemberAccess &&
                                   ((MemberExpression)e.Expression).Expression != null &&
                                   ((MemberExpression)e.Expression).Expression.NodeType == ExpressionType.Parameter;

            if (isMember || isNullableMember)
            {
                Nodes.AddNode(CreateNewMemberNode(e));

                return(e);
            }

            try
            {
                var value = e.Evaluate();
                var constantExpression = Expression.Constant(value);

                return(VisitConstant(constantExpression));
            }
            catch
            {
                var memberNode = CreateNewMemberNode(e);
                Nodes.AddNode(memberNode);

                return(e);
            }
        }
Exemplo n.º 2
0
        protected override Expression VisitMember(MemberExpression node)
        {
            // 1.<>h__TransparentIdentifier3.b.Client.ClientName
            // 2.<>h__TransparentIdentifier3.b.Client.ClientName.Length
            // 3.<>h__TransparentIdentifier3.b.Client.Address.AddressName
            // 4.<>h__TransparentIdentifier3.b.ClientName
            // <>h__TransparentIdentifier2.<>h__TransparentIdentifier3.b.ClientName
            // <>h__TransparentIdentifier2.<>h__TransparentIdentifier3.b.Client.ClientName
            // <>h__TransparentIdentifier2.<>h__TransparentIdentifier3.b.Client.Address.AddressName
            // 5.b.ClientName

            _visitedMark.Add(node);

            if (node == null)
            {
                return(node);
            }
            // => a.ActiveDate == DateTime.Now  => a.State == (byte)state
            if (node.CanEvaluate())
            {
                return(this.VisitConstant(node.Evaluate()));
            }
            // => a.Nullable.Value
            bool isNullable = node.Expression.Type.IsGenericType && node.Member.Name == "Value" && node.Expression.Type.GetGenericTypeDefinition() == typeof(Nullable <>);

            if (isNullable)
            {
                return(this.Visit(node.Expression));
            }
            // => a.Name.Length
            if (TypeUtils.IsPrimitiveType(node.Expression.Type))
            {
                return(_methodVisitor.VisitMemberMember(node));
            }
            // => <>h__3.b.ClientName
            if (!node.Expression.Acceptable())
            {
                return(_builder.AppendMember(node, _aliases));
            }
            // => a.Accounts[0].Markets[0].MarketId
            // => b.Client.Address.AddressName
            Expression objExpression = node.Expression;
            bool       isMethodCall  = objExpression != null && objExpression.NodeType == ExpressionType.Call;

            if (isMethodCall)
            {
                MethodCallExpression methodExpression = objExpression as MethodCallExpression;
                bool isGetItem = methodExpression.IsGetListItem();
                if (isGetItem)
                {
                    objExpression = methodExpression.Object;
                }
            }
            // => b.Client.Address.AddressName
            this.VisitNavMember(objExpression, node.Member.Name);

            return(node);
        }
Exemplo n.º 3
0
                protected override Expression VisitMember(MemberExpression node)
                {
                    if (node.Member.DeclaringType.IsClosureClass())
                    {
                        return(Expression.Constant(node.Evaluate(), node.Type));
                    }

                    return(base.VisitMember(node));
                }
Exemplo n.º 4
0
            private static object Evaluate(MemberExpression node)
            {
                var expression = node.Expression;

                if (node.Member is FieldInfo field && expression.NodeType == ExpressionType.Constant)
                {
                    return(field.GetValue(((ConstantExpression)expression).Value));
                }

                return(node.Evaluate());
            }
Exemplo n.º 5
0
        protected override Expression VisitMember(MemberExpression node)
        {
            // 1.<>h__TransparentIdentifier3.b.Client.ClientName
            // 2.<>h__TransparentIdentifier3.b.Client.ClientName.Length
            // 3.<>h__TransparentIdentifier3.b.Client.Address.AddressName
            // 4.<>h__TransparentIdentifier3.b.ClientName
            // <>h__TransparentIdentifier2.<>h__TransparentIdentifier3.b.ClientName
            // <>h__TransparentIdentifier2.<>h__TransparentIdentifier3.b.Client.ClientName
            // <>h__TransparentIdentifier2.<>h__TransparentIdentifier3.b.Client.Address.AddressName
            // 5.b.ClientName

            if (node == null)
            {
                return(node);
            }
            // 表达式 => a.ActiveDate == DateTime.Now
            if (node.Expression == null)
            {
                return(this.VisitConstant(node.Evaluate()));
            }
            // 表达式 => a.State == (byte)state
            if (node.IsConstant())
            {
                return(this.VisitConstant(node.Evaluate()));
            }
            // 表达式 => a.Name.Length
            if (Reflection.TypeUtils.IsPrimitive(node.Expression.Type))
            {
                return(_provider.MethodVisitor.VisitMemberMember(node, this));
            }
            // 表达式 => <>h__3.b.ClientName
            if (!node.Expression.IsVisitable())
            {
                return(_builder.AppendMember(node, _aliases));
            }
            // 表达式 => b.Client.Address.AddressName
            this.VisitNavigation(node.Expression, node.Member.Name);

            return(node);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 访问字段或者属性表达式
        /// </summary>
        /// <param name="node">字段或者成员表达式</param>
        /// <returns></returns>
        protected override Expression VisitMember(MemberExpression node)
        {
            // 1.<>h__TransparentIdentifier3.b.Client.ClientName
            // 2.<>h__TransparentIdentifier3.b.Client.ClientName.Length
            // 3.<>h__TransparentIdentifier3.b.Client.Address.AddressName
            // 4.<>h__TransparentIdentifier3.b.ClientName
            // <>h__TransparentIdentifier2.<>h__TransparentIdentifier3.b.ClientName
            // <>h__TransparentIdentifier2.<>h__TransparentIdentifier3.b.Client.ClientName
            // <>h__TransparentIdentifier2.<>h__TransparentIdentifier3.b.Client.Address.AddressName
            // 5.b.ClientName


            if (node == null)
            {
                return(node);
            }
            // => a.ActiveDate == DateTime.Now  => a.State == (byte)state
            if (node.CanEvaluate())
            {
                return(this.VisitConstant(node.Evaluate()));
            }
            // => DateTime.Now
            if (node.Type == typeof(DateTime) && node.Expression == null)
            {
                return(this.VisitMethodCall(node, MethodCallType.MemberMember));
            }
            // => a.Nullable.Value
            bool isNullable = node.Expression.Type.IsGenericType && node.Member.Name == "Value" && node.Expression.Type.GetGenericTypeDefinition() == typeof(Nullable <>);

            if (isNullable)
            {
                this.Visit(node.Expression);
                return(node);
            }

            // 记录访问成员栈
            _visitedStack.Add(node);

            // => a.Name.Length
            if (TypeUtils.IsPrimitiveType(node.Expression.Type))
            {
                return(this.VisitMethodCall(node, MethodCallType.MemberMember));
            }
            // => <>h__3.b.ClientName
            if (!node.Expression.Visitable())
            {
                _builder.AppendMember(_ag, node);
                return(node);
            }
            // => a.Accounts[0].Markets[0].MarketId
            // => b.Client.Address.AddressName
            Expression objExpression = node.Expression;
            bool       isMethodCall  = objExpression != null && objExpression.NodeType == ExpressionType.Call;

            if (isMethodCall)
            {
                MethodCallExpression methodExpression = objExpression as MethodCallExpression;
                bool isIndex = methodExpression.IsCollectionIndex();
                if (isIndex)
                {
                    objExpression = methodExpression.Object;
                }
            }
            // => b.Client.Address.AddressName
            this.VisitNavMember(objExpression, TypeUtils.GetFieldName(node.Member, node.Expression.Type));

            return(node);
        }