Esempio n. 1
0
        // When there is more than one property accessor, the last accessor needs to be taken out and added to the binary logical predicate.
        // property(property(property operator value)
        private static IPredicateVisitor CombinePredicates(IPredicateVisitor left, IPredicateVisitor right)
        {
            var containerLeft = (ContainerPredicateVisitor)left;

            IPredicateVisitor parent = containerLeft;

            if (parent == null)
            {
                return(new ContainerPredicateVisitor(right, left));
            }

            IPredicateVisitor         innerContainer    = right;
            ContainerPredicateVisitor combinedContainer = null;

            while (parent != null)
            {
                if (CanBeCombined(parent))
                {
                    var container = (ContainerPredicateVisitor)parent;
                    innerContainer    = new ContainerPredicateVisitor(innerContainer, container.Inner);
                    combinedContainer = new ContainerPredicateVisitor(innerContainer, container.Parent);
                    parent            = container.Parent;
                }
            }

            return(combinedContainer);
        }
        // When there is more than one property accessor, the last accessor needs to be taken out and added to the binary logical predicate.
        // property(property(property operator value)
        private static IPredicateVisitor CombinePredicates(IPredicateVisitor left, string operatorSign, IPredicateVisitor right)
        {
            var containerLeft = (ContainerPredicateVisitor)left;
            IPredicateVisitor      innerLeft = containerLeft.Inner;
            BinaryPredicateVisitor binaryPredicateVisitor = new BinaryPredicateVisitor(innerLeft, operatorSign, right);

            IPredicateVisitor parent = containerLeft.Parent;

            if (parent == null)
            {
                return(new ContainerPredicateVisitor(binaryPredicateVisitor, null));
            }

            IPredicateVisitor         innerContainer    = binaryPredicateVisitor;
            ContainerPredicateVisitor combinedContainer = null;

            while (parent != null)
            {
                if (CanBeCombined(parent))
                {
                    var container = (ContainerPredicateVisitor)parent;
                    innerContainer    = new ContainerPredicateVisitor(innerContainer, container.Inner);
                    combinedContainer = new ContainerPredicateVisitor(innerContainer, container.Parent);
                    parent            = container.Parent;
                }
            }

            return(combinedContainer);
        }
        private static bool ArePropertiesEqual(ContainerPredicateVisitor left, ContainerPredicateVisitor right)
        {
            ConstantPredicateVisitor constantLeft  = left.Parent as ConstantPredicateVisitor;
            ConstantPredicateVisitor constantRight = right.Parent as ConstantPredicateVisitor;

            if (constantLeft != null && constantRight != null)
            {
                return(constantLeft.Constant == constantRight.Constant);
            }

            return(false);
        }
        public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory)
        {
            if (expression is MethodCallExpression methodCallExpression)
            {
                if (methodCallExpression.Object is MemberExpression memberExpression)
                {
                    ContainerPredicateVisitor parentAccessor           = predicateVisitorFactory.Create(memberExpression) as ContainerPredicateVisitor;
                    IPredicateVisitor         constantPredicateVisitor = predicateVisitorFactory.Create(methodCallExpression.Arguments[0]);
                    return(new ContainerPredicateVisitor(RemoveQuotes(constantPredicateVisitor), parentAccessor));
                }
            }

            return(null);
        }
Esempio n. 5
0
        public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory)
        {
            MethodCallExpression methodCallExpression = expression as MethodCallExpression;

            if (methodCallExpression == null)
            {
                return(null);
            }

            IPredicateVisitor         inner = predicateVisitorFactory.Create(methodCallExpression.Arguments[0]);
            IPredicateVisitor         innerWithoutQuotes = RemoveQuotes(inner);
            IPredicateVisitor         parent             = predicateVisitorFactory.Create(methodCallExpression.Object);
            ContainerPredicateVisitor container          = new ContainerPredicateVisitor(innerWithoutQuotes, parent);

            return(container);
        }
Esempio n. 6
0
        public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory)
        {
            MethodCallExpression methodCallExpression = expression as MethodCallExpression;

            if (methodCallExpression == null)
            {
                return(null);
            }

            string methodName = this.AllowedMethods[methodCallExpression.Method.Name];
            ConstantPredicateVisitor methodNameConstant = new ConstantPredicateVisitor(methodName);
            IPredicateVisitor        methodCaller       = predicateVisitorFactory.Create(methodCallExpression.Arguments[0]);
            IPredicateVisitor        methodArguments    = predicateVisitorFactory.Create(methodCallExpression.Arguments[1]);

            ContainerPredicateVisitor container = new ContainerPredicateVisitor(methodArguments, methodNameConstant, true);
            BinaryPredicateVisitor    binary    = new BinaryPredicateVisitor(methodCaller, string.Empty, container);

            return(binary);
        }
        private static IPredicateVisitor CombinePredicateVisitors(IPredicateVisitor left, string operatorSign, IPredicateVisitor right)
        {
            IPredicateVisitor         innerLeft  = left;
            IPredicateVisitor         innerRight = right;
            ContainerPredicateVisitor container  = null;

            while (innerLeft is ContainerPredicateVisitor containerLeft && innerRight is ContainerPredicateVisitor containerRight)
            {
                innerLeft  = containerLeft.Inner;
                innerRight = containerRight.Inner;
                container  = new ContainerPredicateVisitor(containerLeft.Parent, container);
            }

            if (innerLeft is BinaryPredicateVisitor binaryLeft && innerRight is BinaryPredicateVisitor binaryRight)
            {
                BinaryPredicateVisitor binaryPredicateVisitor = new BinaryPredicateVisitor(innerLeft, operatorSign, innerRight);

                return(CombinePredicates(container, binaryPredicateVisitor));
            }

            return(null);
        }