Exemple #1
0
        public void StringFormat()
        {
            var formatToConcat = DefaultRewrite.StringFormat;

            Expression <Func <string, string, string> > test2 = (a, b) => a + b;

            Expression <Func <string, string, string> > test = (a, b) => string.Format("{0} LIKE {1}", a, b);
            var ret = Rewriter.GlobalApplyRule(test.Body, formatToConcat, x => x);

            Assert.AreEqual("((a + \" LIKE \") + b)", ret.ToString());
        }
Exemple #2
0
        public void RewriteSimple()
        {
            var rule = RewriteRule.Create("", (bool x) => true || x, x => true);
            var a    = false;

            Expression <Func <bool> > expr = () => true || a;
            var ret = Rewriter.GlobalApplyRule(expr.Body, rule, x => x);
            var str = ret.ToString();

            Assert.AreEqual(str, "True");
        }
Exemple #3
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());
        }
Exemple #4
0
        public void RewriteArgs()
        {
            var hola = "Hola";
            var rafa = "Rafa";
            Expression <Func <string> > test = () => $"({hola}, {rafa})" + typeof(string).Name;
            var rule = RewriteRule.Create("", (bool x) => x || x, x => x);

            {
                Expression <Func <bool, bool, bool> > expr = (a, b) => a || a;
                var ret = Rewriter.GlobalApplyRule(expr.Body, rule, x => x);
                var str = ret.ToString();
                Assert.AreEqual(str, "a");
            }

            {
                Expression <Func <bool, bool, bool> > expr = (a, b) => a || b;
                var ret = Rewriter.GlobalApplyRule(expr.Body, rule, x => x);
                Assert.AreEqual(ret, expr.Body);
            }
        }