Esempio n. 1
0
        // 访问表达式树后自动删掉访问的成员痕迹
        protected void VisitWithoutRemark(Action <object> visit)
        {
            int visitedQty = _visitedMark.Count;

            visit(null);
            if (_visitedMark.Count != visitedQty)
            {
                _visitedMark.Remove(_visitedMark.Count - visitedQty);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///  将调度到此类中更专用的访问方法之一的表达式。
        /// </summary>
        /// <param name="node">方法节点</param>
        /// <param name="router">方法路由</param>
        /// <returns></returns>
        public Expression Visit(Expression node, MethodCall router)
        {
            int        visitedQty = _visitedMark.Count;
            Expression newNode    = null;

            if (router == MethodCall.Coalesce)
            {
                newNode = this.VisitCoalesce((BinaryExpression)node);
            }
            else if (router == MethodCall.EqualNull)
            {
                newNode = this.VisitEqualNull((BinaryExpression)node);
            }
            else if (router == MethodCall.MethodCall)
            {
                newNode = this.VisitMethodCall((MethodCallExpression)node);
            }
            else if (router == MethodCall.BinaryCall)
            {
                newNode = this.VisitMethodCall((BinaryExpression)node);
            }
            else if (router == MethodCall.MemberMember)
            {
                newNode = this.VisitMemberMember((MemberExpression)node);
            }
            else if (router == MethodCall.Unary)
            {
                newNode = this.VisitUnary((UnaryExpression)node);
            }

            // 自身已构成布尔表达式的则需要删除它本身所产生的访问链
            if (_visitedMark.Count != visitedQty)
            {
                bool b = router != MethodCall.Unary;
                if (b && router == MethodCall.MethodCall)
                {
                    var m = (MethodCallExpression)node;
                    b = _removeVisitedMethods.Contains(m.Method.Name);
                }

                if (b)
                {
                    _visitedMark.Remove(_visitedMark.Count - visitedQty);
                }
            }
            return(newNode);
        }