Exemple #1
0
        static void Main(string[] args)
        {
            var cc = new CompiledExpression()
            {
                StringToParse = "Convert.ToBoolean(obj.result)==true"
            };
            object obj = new objHolder()
            {
                result = true
            };

            cc.RegisterType("obj", obj);
            cc.RegisterDefaultTypes();
            var result = cc.Eval();

            var x = new List <String>()
            {
                "Hello", "There", "World"
            };
            dynamic scope = new ExpandoObject();

            scope.x = x;
            var data = new MyClass {
                Value = () => false
            };
            var item = new MyClass {
                Value = () => true
            };

            scope.data = data;
            scope.item = item;
            scope.i    = 1;
            var a = scope.data.Value() && scope.item.Value();

            //var b = !scope.data.Value() || scope.item.Value();

            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
            var pi   = Convert.ToString(3.141592654);
            var xs   = 2d;
            var pipi = 3.141592654.ToString();
            var c0   = new CompiledExpression()
            {
                StringToParse = "3.141592654.ToString()"
            };
            var pi2 = c0.Eval();

            var p = scope.x[0];

            // (data.Value && !item.Value) ? 'yes' : 'no'
            var c = new CompiledExpression()
            {
                StringToParse = "data.Foo(30 + data.Bar(10))"
            };

            c.RegisterType("data", data);
            Console.WriteLine(data.X);
            c.Eval();
            //c.Call();
            Console.WriteLine(data.X);

            var c8 = new CompiledExpression()
            {
                StringToParse = "data.X  + '%'"
            };

            c8.RegisterType("data", data);
            Console.WriteLine(data.X);
            var cr = c8.Eval();

            Console.WriteLine(data.X);


            var c1 = new CompiledExpression()
            {
                StringToParse = "Foo()"
            };
            var f1 = c1.ScopeCompileCall <MyClass>();

            Console.WriteLine(data.X);
            f1(data);
            Console.WriteLine(data.X);
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
            var fr = new CultureInfo("fr-FR");

            var qq   = (25.82).ToString("0.00", fr) + "px";
            var test = "(25.82).ToString('0.00') + 'px'";
            var cx   = new CompiledExpression()
            {
                StringToParse = "int.Parse('25.82', fr)"
            };

            cx.RegisterType("fr", fr);


            var c2 = new CompiledExpression()
            {
                StringToParse = "data.Foo()"
            };
            var y  = 12 + "px";
            var f2 = c2.ScopeCompileCall();

            Console.WriteLine(scope.data.X);
            f2(scope);
            Console.WriteLine(scope.data.X);

            scope.c = new c();

            var c3 = new CompiledExpression()
            {
                StringToParse = "c.sum(1,2,3,4,5,6,7,8)"
            };
            var f3 = c3.ScopeCompile();
            var x3 = f3(scope);

            var c4 = new CompiledExpression()
            {
                StringToParse = "c.sum(1,2)"
            };
            var f4 = c4.ScopeCompile();
            var x4 = f4(scope);

            var c5 = new CompiledExpression()
            {
                StringToParse = "c.sum(1.0d,2.0d)"
            };
            var f5 = c5.ScopeCompile();
            var x5 = f5(scope);

            var c6 = new CompiledExpression()
            {
                StringToParse = "c.sum(1,2.0d)"
            };
            var f6 = c6.ScopeCompile();
            var x6 = f6(scope);

            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var cc = new CompiledExpression() { StringToParse = "Convert.ToBoolean(obj.result)==true" };
            object obj = new objHolder() { result = true };
            cc.RegisterType("obj", obj);
            cc.RegisterDefaultTypes();
            var result = cc.Eval();

            var x = new List<String>() { "Hello", "There", "World" };
            dynamic scope = new ExpandoObject();
            scope.x = x;
            var data = new MyClass { Value = () => false };
            var item = new MyClass { Value = () => true };
            scope.data = data;
            scope.item = item;
            scope.i = 1;
            var a = scope.data.Value() && scope.item.Value();
            //var b = !scope.data.Value() || scope.item.Value();

            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
            var pi = Convert.ToString(3.141592654);
            var xs = 2d;
            var pipi = 3.141592654.ToString();
            var c0 = new CompiledExpression() { StringToParse = "3.141592654.ToString()" };
            var pi2 = c0.Eval();

            var p = scope.x[0];

            // (data.Value && !item.Value) ? 'yes' : 'no'
            var c = new CompiledExpression() { StringToParse = "data.Foo(30 + data.Bar(10))" };
            c.RegisterType("data", data);
            Console.WriteLine(data.X);
            c.Eval();
            //c.Call();
            Console.WriteLine(data.X);

            var c8= new CompiledExpression() { StringToParse = "data.X  + '%'" };
            c8.RegisterType("data", data);
            Console.WriteLine(data.X);
            var cr = c8.Eval();
            Console.WriteLine(data.X);

            var c1 = new CompiledExpression() { StringToParse = "Foo()" };
            var f1 = c1.ScopeCompileCall<MyClass>();
            Console.WriteLine(data.X);
            f1(data);
            Console.WriteLine(data.X);
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
            var fr = new CultureInfo("fr-FR");

            var qq = (25.82).ToString("0.00", fr) + "px";
            var test = "(25.82).ToString('0.00') + 'px'";
            var cx = new CompiledExpression() { StringToParse = "int.Parse('25.82', fr)" };
            cx.RegisterType("fr", fr);

            var c2 = new CompiledExpression() { StringToParse = "data.Foo()" };
            var y = 12 + "px";
            var f2 = c2.ScopeCompileCall();
            Console.WriteLine(scope.data.X);
            f2(scope);
            Console.WriteLine(scope.data.X);

            scope.c = new c();

            var c3 = new CompiledExpression() { StringToParse = "c.sum(1,2,3,4,5,6,7,8)" };
            var f3 = c3.ScopeCompile();
            var x3 = f3(scope);

            var c4 = new CompiledExpression() { StringToParse = "c.sum(1,2)" };
            var f4 = c4.ScopeCompile();
            var x4 = f4(scope);

            var c5 = new CompiledExpression() { StringToParse = "c.sum(1.0d,2.0d)" };
            var f5 = c5.ScopeCompile();
            var x5 = f5(scope);

            var c6 = new CompiledExpression() { StringToParse = "c.sum(1,2.0d)" };
            var f6 = c6.ScopeCompile();
            var x6 = f6(scope);

            Console.ReadLine();
        }