示例#1
0
        public void test_THAT_in_list_expression_IS_valid()
        {
            var a = new InAnalyzer(null, null);
            Expression <Func <SPListItem, bool> > expr = x => getArray().Contains((int)x["test"]);

            Assert.IsTrue(a.IsValid(expr));
        }
示例#2
0
        public void test_THAT_in_not_const_int_yield_expression_IS_valid()
        {
            var a = new InAnalyzer(null, null);
            Expression <Func <SPListItem, bool> > expr = x => iterator().Cast <int>().Contains((int)x["test"]);

            Assert.IsTrue(a.IsValid(expr));
        }
示例#3
0
        public void test_THAT_in_const_string_expression_IS_valid()
        {
            var a = new InAnalyzer(null, null);
            IEnumerable <string> values = new [] { "1", "2", "3" };
            Expression <Func <SPListItem, bool> > expr = x => values.Contains((string)x["test"]);

            Assert.IsTrue(a.IsValid(expr));
        }
示例#4
0
        public void test_THAT_in_not_const_int_expression_IS_valid()
        {
            var             a      = new InAnalyzer(null, null);
            int             i      = 1;
            Func <int, int> f      = p => (p + 1);
            IEnumerable     values = new[] { i, f(2), foo() };
            Expression <Func <SPListItem, bool> > expr = x => values.Cast <int>().Contains((int)x["test"]);

            Assert.IsTrue(a.IsValid(expr));
        }
示例#5
0
        public IAnalyzer Create(LambdaExpression expr)
        {
            ExpressionType exprType = expr.Body.NodeType;

            if (exprType == ExpressionType.AndAlso)
            {
                return(new AndAlsoAnalyzer(this.operationResultBuilder, this));
            }
            if (exprType == ExpressionType.OrElse)
            {
                return(new OrElseAnalyzer(this.operationResultBuilder, this));
            }
            if (exprType == ExpressionType.NewArrayInit)
            {
                return(new ArrayAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }
            if (exprType == ExpressionType.GreaterThanOrEqual)
            {
                return(new GeqAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }
            if (exprType == ExpressionType.GreaterThan)
            {
                return(new GtAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }
            if (exprType == ExpressionType.LessThanOrEqual)
            {
                return(new LeqAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }
            if (exprType == ExpressionType.LessThan)
            {
                return(new LtAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }

            // it is important to check NotIncludes before Equality because sometimes !x[].Includes() is interpreted as x[].Includes() == False
            // and sometimes as Not(x[])
            var includesAnalyzer = new IncludesAnalyzer(operationResultBuilder, operandBuilder);

            if (includesAnalyzer.IsValid(expr))
            {
                return(includesAnalyzer);
            }

            var notIncludesAnalyzer = new NotIncludesAnalyzer(operationResultBuilder, operandBuilder);

            if (notIncludesAnalyzer.IsValid(expr))
            {
                return(notIncludesAnalyzer);
            }

            // it is not enough to check ExpressionType for IsNull operation.
            // We need also to check that right operand is null
            IsNullAnalyzer isNullAnalyzer;

            if (this.isNullExpression(expr, out isNullAnalyzer))
            {
                return(isNullAnalyzer);
            }
            // note that it is important to have check on IsNull before check on ExpressionType.Equal.
            // Because x["foo"] == null is also ExpressionType.Equal, but it should be translated
            // into <IsNull> instead of <Eq>
            if (exprType == ExpressionType.Equal)
            {
                return(new EqAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }

            // it is not enough to check ExpressionType for IsNotNull operation.
            // We need also to check that right operand is null
            IsNotNullAnalyzer isNotNullAnalyzer;

            if (this.isNotNullExpression(expr, out isNotNullAnalyzer))
            {
                return(isNotNullAnalyzer);
            }
            // note that it is important to have check on IsNotNull before check on ExpressionType.NotEqual.
            // Because x["foo"] != null is also ExpressionType.NotEqual, but it should be translated
            // into <IsNotNull> instead of <Neq>
            if (exprType == ExpressionType.NotEqual)
            {
                return(new NeqAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }

            var beginsWithAnalyzer = new BeginsWithAnalyzer(operationResultBuilder, operandBuilder);

            if (beginsWithAnalyzer.IsValid(expr))
            {
                return(beginsWithAnalyzer);
            }

            var containsAnalyzer = new ContainsAnalyzer(operationResultBuilder, operandBuilder);

            if (containsAnalyzer.IsValid(expr))
            {
                return(containsAnalyzer);
            }

            var dateRangesOverlapAnalyzer = new DateRangesOverlapAnalyzer(operationResultBuilder, operandBuilder);

            if (dateRangesOverlapAnalyzer.IsValid(expr))
            {
                return(dateRangesOverlapAnalyzer);
            }

            var membershipAnalyzer = new MembershipAnalyzer(operationResultBuilder, operandBuilder);

            if (membershipAnalyzer.IsValid(expr))
            {
                return(membershipAnalyzer);
            }

            var inAnalyzer = new InAnalyzer(operationResultBuilder, operandBuilder);

            if (inAnalyzer.IsValid(expr))
            {
                return(inAnalyzer);
            }

            var joinAnalyzer = new JoinAnalyzer(operationResultBuilder, operandBuilder);

            if (joinAnalyzer.IsValid(expr))
            {
                return(joinAnalyzer);
            }

            var projectedFieldAnalyzer = new ProjectedFieldAnalyzer(operationResultBuilder, operandBuilder);

            if (projectedFieldAnalyzer.IsValid(expr))
            {
                return(projectedFieldAnalyzer);
            }

            throw new NonSupportedExpressionTypeException(exprType);
        }