Ejemplo n.º 1
0
        public void InvokeRule()
        {
            Expression <Func <int, int> > sumar = x => (x + 10);
            Expression <Func <int, int> > test  = y => sumar.Invoke(y * 3);

            var rule     = DefaultRewrite.InvokeRule(null);
            var ret      = Rewriter.GlobalApplyRule(test.Body, rule, x => x);
            var expected = "((y * 3) + 10)";

            Assert.AreEqual(expected, ret.ToString());
        }
Ejemplo n.º 2
0
        public void InvokeRecRule()
        {
            Expression <Func <int, int, int> > sumar   = (a, b) => a + b;
            Expression <Func <int, int> >      sumar10 = x => sumar.Invoke(x, 10);
            Expression <Func <int, int> >      test    = y => sumar10.Invoke(y * 3);

            var rules = new[] {
                DefaultRewrite.InvokeRule(null)
            };

            var ret      = ApplyRules(test, rules);
            var expected = "y => ((y * 3) + 10)";

            Assert.AreEqual(expected, ret.ToString());
        }
Ejemplo n.º 3
0
        public SqlRewriteVisitor(SqlExprParams pars)
        {
            var exprParamRules = SqlFunctions.ExprParamsRules(pars);

            //The order of the rule passes is important to the performance and correctness!

            rules = new List <IEnumerable <RewriteRule> >();
            //Primero quita los invokes
            rules.Add(
                new[]
            {
                DefaultRewrite.InvokeRule(exprParamRules)
            });

            rules.Add(DefaultRewrite.BooleanSimplify);

            rules.Add(
                exprParamRules
                );

            rules.Add(
                SqlFunctions.rawAtom
                .Concat(SqlFunctions.AtomInvokeParam(pars))
                .Concat(
                    new[]
            {
                SqlConst.constToSqlRule,
                DefaultRewrite.StringFormat,
                SqlFunctions.rawCallRule
            }
                    )
                .Concat(SqlOperators.eqNullRule)
                .Concat(SqlOperators.nullableRules)
                .Concat(SqlOperators.unaryRules)
                .Concat(SqlOperators.binaryRules)
                .Concat(SqlStar.starRules)
                .Concat(SqlOperators.compareTo)
                .Concat(SqlFunctions.stringCalls)
                .Concat(SqlFunctions.subqueryExprs)
                .Concat(SqlFunctions.sqlCalls)
                .Concat(SqlFunctions.AtomRawRule(pars))
                .ToList()
                )
            ;
        }
Ejemplo n.º 4
0
        public static Expression VisitFromItem(Expression expr)
        {
            var ret = Rewriter.RecApplyRules(expr, new[] { DefaultRewrite.InvokeRule(null) }, x => false);

            return(ret);
        }