Exemple #1
0
        public void test_THAT_join_with_foreign_and_primary_lists_IS_valid()
        {
            var a = new JoinAnalyzer(null, null);
            Expression <Func <SPListItem, object> > expr = x => x["test"].PrimaryList("foo").ForeignList("bar");

            Assert.IsTrue(a.IsValid(expr));
        }
Exemple #2
0
        public void test_THAT_join_with_foreign_and_primary_lists_and_non_constants_params_IS_valid()
        {
            Func <string> f = () => "foo";
            var           a = new JoinAnalyzer(null, null);
            Expression <Func <SPListItem, object> > expr = x => x[f()].PrimaryList(f()).ForeignList(f());

            Assert.IsTrue(a.IsValid(expr));
        }
        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);
        }