Example #1
0
        public void StringOperator()
        {
            Delegate test = EHandler.CreateMethod <string>((il) =>
            {
                EVar temp_var1 = "Hello ";
                EVar temp_var2 = EVar.CreateVarFromObject("World");
                (temp_var1 + temp_var2)();
            }).Compile();
            Func <string> action = (Func <string>)test;

            Assert.Equal("Hello World", action());
        }
Example #2
0
        public static void TestSingle()
        {
            //动态创建Action委托
            Delegate newMethod = EHandler.CreateMethod <ENull>((il) =>
            {
                //创建没有临时变量的普通入栈变量(没有临时变量,所以自加操作没有意义)
                EVar intHandler = 1;
                //创建函数操作句柄
                EMethod method = typeof(Console);
                //输出intHandler的时候,让变量做加法运算。
                method.ExecuteMethod <int>("WriteLine", intHandler + 665);
                //结果:666;
            }).Compile();

            ((Action)newMethod)();

            //动态创建Action<int,string>委托
            Delegate newMethod1 = EHandler.CreateMethod <ENull>((il) =>
            {
                //创建有临时变量的普通入栈变量(自加操作可以被自身储存) 也就是说可以使用store存储函数
                //int i = 664;
                EVar intHandler = EVar.CreateVarFromObject(664);
                //i++;
                intHandler++;
                //i=i+1;
                intHandler.Store(intHandler + 1);
                //创建函数操作句柄
                EMethod method = typeof(Console);
                //输出intHandler
                method.ExecuteMethod <int>("WriteLine", intHandler);
                //结果:666
            }).Compile();

            ((Action)newMethod1)();

            ////动态创建Action委托
            //Delegate newMethod0 = EHandler.CreateMethod<ENull>((il) => { }).Compile();

            ////动态创建Action<string,int>委托
            //Delegate newMethod1 = EHandler.CreateMethod<string,int,ENull>((il) => { }).Compile();

            ////动态创建Func<string>委托
            //Delegate newMethod2 = EHandler.CreateMethod<string>((il) => { }).Compile();

            ////动态创建Func<string,TestClass>委托
            //Delegate newMethod3 = EHandler.CreateMethod<string, TestClass>((il) => { }).Compile();
        }
Example #3
0
        public static void TestIf()
        {
            Delegate showResult = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod method = typeof(Console);

                EVar emit_A = EVar.CreateWithoutTempVar(10);
                EVar emit_B = EVar.CreateVarFromObject(20);

                TestClass t = new TestClass()
                {
                    Field = 10
                };
                t.PropertyName = "3";
                EModel model   = EModel.CreateModelFromObject(t);

                EJudge.If(emit_A == model.DLoadValue("Field").Operator)(() =>
                {
                    method.ExecuteMethod <string>("WriteLine", "相等");
                }).ElseIf(emit_A > emit_B)(() =>
                {
                    method.ExecuteMethod <int>("WriteLine", emit_A);
                }).Else(() =>
                {
                    method.ExecuteMethod <int>("WriteLine", emit_B);
                });



                EVar string_A = "6";
                EVar string_B = "2";

                EJudge.If(string_A == "1")(() =>
                {
                    method.ExecuteMethod <string>("WriteLine", string_A);
                }).ElseIf(string_A == model.DLoadValue("PropertyName").Operator)(() =>
                {
                    method.ExecuteMethod <string>("WriteLine", string_A);
                }).Else(() =>
                {
                    method.ExecuteMethod <string>("WriteLine", string_B);
                });
            }).Compile();

            ((Action)showResult)();
        }
Example #4
0
        public static void TestNull()
        {
            //动态创建Action委托
            Delegate newMethod = EHandler.CreateMethod <ENull>((il) =>
            {
                //创建没有临时变量的普通入栈变量(没有临时变量,所以自加操作没有意义)
                EVar intHandler = EVar.CreateVarFromObject("2");
                //创建函数操作句柄
                EMethod method = typeof(Console);
                //输出intHandler
                method.ExecuteMethod <string>("WriteLine", intHandler);
                //填空值string=null
                intHandler.Store(ENull.Value);
                method.ExecuteMethod <string>("WriteLine", intHandler);
            }).Compile();

            ((Action)newMethod)();
        }
Example #5
0
        public void SOTest()
        {
            ComplexStructModel model = new ComplexStructModel();

            model.FieldModel = new FieldClass()
            {
                RefField = "Hello", ValueField = ulong.MaxValue - 1
            };
            model.PropertyModel = new PropertyClass()
            {
                RefProperty = "Hello", ValueProperty = ulong.MinValue + 1
            };
            model.MethodModel        = new MethodClass();
            ComplexStructModel.Model = model;

            Delegate test = EHandler.CreateMethod <ComplexStructModel>((il) =>
            {
                EVar ulongHandler           = (ulong)1;
                EVar ulongHandlerFromObject = EVar.CreateVarFromObject((ulong)1);
                EVar stringHandler          = " World";
                EModel modelHandler         = EModel.CreateModelFromObject(model);
                modelHandler.Load("FieldModel").Set("ValueField", modelHandler.DLoad("FieldModel").DLoad("ValueField").Operator + (ulong)1);
                modelHandler.DLoad("FieldModel").DLoad("ValueField").Operator--;
                modelHandler.DLoad("FieldModel").DLoad("ValueField").Operator++;

                modelHandler.Load("PropertyModel").Set("ValueProperty", modelHandler.DLoad("PropertyModel").DLoad("ValueProperty").Operator - (ulong)1);
                modelHandler.DLoad("PropertyModel").DLoad("ValueProperty").Operator++;
                modelHandler.DLoad("PropertyModel").DLoad("ValueProperty").Operator--;

                modelHandler.Load("PropertyModel").Set("RefProperty", modelHandler.DLoad("PropertyModel").DLoad("RefProperty").Operator + " World");

                modelHandler.Load("FieldModel").Set("RefField", modelHandler.DLoad("FieldModel").DLoad("RefField").Operator + stringHandler);
                modelHandler.DLoad("Model").DLoad("FieldModel").DLoad("ValueField").Operator++;
                modelHandler.Load();
            }).Compile();
            Func <ComplexStructModel> action = (Func <ComplexStructModel>)test;
            ComplexStructModel        result = action();

            Assert.Equal(ulong.MaxValue, result.FieldModel.ValueField);
            Assert.Equal(ulong.MinValue, result.PropertyModel.ValueProperty);
            Assert.Equal("Hello World", result.FieldModel.RefField);
            Assert.Equal("Hello World", result.PropertyModel.RefProperty);
            Assert.Equal(ulong.MaxValue, ComplexStructModel.Model.FieldModel.ValueField);
        }
Example #6
0
        public static void TestOperator()
        {
            Delegate showResult = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod method = typeof(Console);
                EVar emit_A    = EVar.CreateWithoutTempVar(12);
                EVar emit_B    = EVar.CreateVarFromObject(13);
                method.ExecuteMethod <int>("WriteLine", emit_A + emit_B);
                method.ExecuteMethod <int>("WriteLine", emit_A + 1);
                method.ExecuteMethod <int>("WriteLine", 1 + 1);
                method.ExecuteMethod <int>("WriteLine", emit_B++);
            }).Compile();

            ((Action)showResult)();

            TestClass t = new TestClass();

            t.Field    = 10;
            t.Property = 20;

            TestStruct t2 = new TestStruct();

            t2.Field    = 90;
            t2.Property = 80;
            t.Next      = t2;
            showResult  = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod method = typeof(Console);
                EVar emit_A    = EVar.CreateWithoutTempVar(12);
                EVar emit_B    = EVar.CreateVarFromObject(13);
                EModel model   = EModel.CreateModelFromObject(t);

                method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field").DelayAction);
                method.ExecuteMethod <int>("WriteLine", (model.DLoadValue("Field").Operator++).DelayAction);
                method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field") + emit_A);
                method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field").Operator + 10);
                method.ExecuteMethod <int>("WriteLine", (model.DLoad("Next").DLoadValue("Property").Operator++).DelayAction);
                method.ExecuteMethod <int>("WriteLine", (model.DLoad("Next").DLoadValue("Property").Operator + 10));
                method.ExecuteMethod <int>("WriteLine", emit_B + model.DLoadValue("Property").Operator);
                method.ExecuteMethod <int>("WriteLine", emit_B++);
            }).Compile();
            ((Action)showResult)();
        }
Example #7
0
        public void ByteOperator()
        {
            Delegate test = EHandler.CreateMethod <byte>((il) =>
            {
                EVar temp_var1 = (byte)15;
                EVar temp_var2 = EVar.CreateVarFromObject((byte)10);
                EVar temp_var3 = (byte)5;
                temp_var2.Store(temp_var1 + temp_var2);
                temp_var2.Store(temp_var2 / 5);
                temp_var2.Store(temp_var2 * 50);
                temp_var2.Store(temp_var2 + temp_var3);
                temp_var2--;
                temp_var2++;
                temp_var2.Load();
            }).Compile();
            Func <byte> action = (Func <byte>)test;

            Assert.Equal(byte.MaxValue, action());
        }
Example #8
0
        public void FloatOperator()
        {
            Delegate test = EHandler.CreateMethod <float>((il) =>
            {
                EVar temp_var1 = (float)15;
                EVar temp_var2 = EVar.CreateVarFromObject((float)10);
                EVar temp_var3 = (float)3.5;
                temp_var2.Store(temp_var1 + temp_var2);
                temp_var2.Store(temp_var2 / (float)5);
                temp_var2.Store(temp_var2 - temp_var3);
                temp_var2.Store(temp_var2 * 3.0);
                temp_var2--;
                temp_var2++;
                temp_var2.Load();
            }).Compile();
            Func <float> action = (Func <float>)test;

            Assert.Equal((float)4.5, action());
        }
Example #9
0
        public void DoubleOperator()
        {
            Delegate test = EHandler.CreateMethod <double>((il) =>
            {
                EVar temp_var1 = (double)15;
                EVar temp_var2 = EVar.CreateVarFromObject((double)10);
                EVar temp_var3 = 3.5;
                temp_var2.Store(temp_var1 + temp_var2);
                temp_var2.Store(temp_var2 / (double)5);
                temp_var2.Store(temp_var2 - temp_var3);
                temp_var2.Store(temp_var2 * 3.0);
                temp_var2--;
                temp_var2++;
                temp_var2.Load();
            }).Compile();
            Func <double> action = (Func <double>)test;

            Assert.Equal(4.5, action());
        }
Example #10
0
        public void LongOperator()
        {
            Delegate test = EHandler.CreateMethod <long>((il) =>
            {
                EVar temp_var1 = (long)15;
                EVar temp_var2 = EVar.CreateVarFromObject((long)10);
                EVar temp_var3 = (long)2;
                temp_var2.Store(temp_var1 + temp_var2);
                temp_var2.Store(temp_var2 / (long)5);
                temp_var2.Store(temp_var2 * 1844674407370955161);
                temp_var2.Store(temp_var2 + temp_var3);
                temp_var2--;
                temp_var2++;
                temp_var2.Load();
            }).Compile();
            Func <long> action = (Func <long>)test;

            Assert.Equal(long.MaxValue, action());
        }
Example #11
0
        public void ULongOperator()
        {
            Delegate test = EHandler.CreateMethod <ulong>((il) =>
            {
                EVar temp_var1 = (ulong)15;
                EVar temp_var2 = EVar.CreateVarFromObject((ulong)10);
                EVar temp_var3 = (ulong)0;
                temp_var2.Store(temp_var1 + temp_var2);
                temp_var2.Store(temp_var2 / (ulong)5);
                temp_var2.Store(temp_var2 * 3689348814741910323);
                temp_var2.Store(temp_var2 + temp_var3);
                temp_var2--;
                temp_var2++;
                temp_var2.Load();
            }).Compile();
            Func <ulong> action = (Func <ulong>)test;

            Assert.Equal(ulong.MaxValue, action());
        }
Example #12
0
        public void ShortOperator()
        {
            Delegate test = EHandler.CreateMethod <short>((il) =>
            {
                EVar temp_var1 = (short)15;
                EVar temp_var2 = EVar.CreateVarFromObject((short)10);
                EVar temp_var3 = (short)2;
                temp_var2.Store(temp_var1 + temp_var2);
                temp_var2.Store(temp_var2 / 5);
                temp_var2.Store(temp_var2 * 6553);
                temp_var2.Store(temp_var2 + temp_var3);
                temp_var2--;
                temp_var2++;
                temp_var2.Load();
            }).Compile();
            Func <short> action = (Func <short>)test;

            Assert.Equal(short.MaxValue, action());
        }
Example #13
0
        public void UIntOperator()
        {
            Delegate test = EHandler.CreateMethod <uint>((il) =>
            {
                EVar temp_var1 = (uint)15;
                EVar temp_var2 = EVar.CreateVarFromObject((uint)10);
                EVar temp_var3 = (uint)0;
                temp_var2.Store(temp_var1 + temp_var2);
                temp_var2.Store(temp_var2 / 5);
                temp_var2.Store(temp_var2 * 858993459);
                temp_var2.Store(temp_var2 + temp_var3);
                temp_var2--;
                temp_var2++;
                temp_var2.Load();
            }).Compile();
            Func <uint> action = (Func <uint>)test;

            Assert.Equal(uint.MaxValue, action());
        }
Example #14
0
        public void ShowInt()
        {
            //测试int上限 无临时变量
            Delegate test = EHandler.CreateMethod <int>((il) => {
                EVar temp_var = int.MaxValue;
                EMethod.Load(typeof(Console)).ExecuteMethod <int>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <int> action = (Func <int>)test;

            Assert.Equal(int.MaxValue, action());

            //测试int下限 有临时变量
            Delegate test2 = EHandler.CreateMethod <int>((il) => {
                EVar temp_var = EVar.CreateVarFromObject(int.MinValue);
                EMethod.Load(typeof(Console)).ExecuteMethod <int>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <int> action2 = (Func <int>)test2;

            Assert.Equal(int.MinValue, action2());
        }
Example #15
0
        public static void TestWhile()
        {
            Delegate showResult = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod method = typeof(Console);

                EVar emit_A = EVar.CreateWithoutTempVar(16);
                EVar emit_B = EVar.CreateVarFromObject(20);
                ELoop.While(emit_A < emit_B)(() =>
                {
                    method.ExecuteMethod <int>("WriteLine", emit_B);
                    emit_B--;
                });


                TestClass t = new TestClass()
                {
                    Field = 10
                };
                EModel model = EModel.CreateModelFromObject(t);
                ELoop.While(model.DLoadValue("Field").Operator < emit_B)(() =>
                {
                    //这里需要传递委托,不传递委托则返回的是model类型而不是int类型
                    method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field").DelayAction);
                    model.DLoadValue("Field").Operator++;
                });

                ELoop.While(model.DLoadValue("Field").Operator != 25)(() =>
                {
                    method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field").DelayAction);
                    model.DLoadValue("Field").Operator++;
                });
            }).Compile();

            ((Action)showResult)();
        }
Example #16
0
        public void ShowBoolean()
        {
            //测试float上限 无临时变量
            Delegate test = EHandler.CreateMethod <bool>((il) =>
            {
                EVar temp_var = true;
                EMethod.Load(typeof(Console)).ExecuteMethod <bool>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <bool> action = (Func <bool>)test;

            Assert.Equal(true, action());

            //测试float下限 有临时变量
            Delegate test2 = EHandler.CreateMethod <bool>((il) =>
            {
                EVar temp_var = EVar.CreateVarFromObject(false);
                EMethod.Load(typeof(Console)).ExecuteMethod <bool>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <bool> action2 = (Func <bool>)test2;

            Assert.Equal(false, action2());
        }
Example #17
0
        public void ShowChar()
        {
            //测试char 无临时变量
            Delegate test = EHandler.CreateMethod <char>((il) =>
            {
                EVar temp_var = 'a';
                EMethod.Load(typeof(Console)).ExecuteMethod <char>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <char> action = (Func <char>)test;

            Assert.Equal('a', action());

            //测试string 有临时变量
            Delegate test2 = EHandler.CreateMethod <char>((il) =>
            {
                EVar temp_var = EVar.CreateVarFromObject('`');
                EMethod.Load(typeof(Console)).ExecuteMethod <char>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <char> action2 = (Func <char>)test2;

            Assert.Equal('`', action2());
        }
Example #18
0
        public void ShowString()
        {
            //测试string 无临时变量
            Delegate test = EHandler.CreateMethod <string>((il) =>
            {
                EVar temp_var = string.Empty;
                EMethod.Load(typeof(Console)).ExecuteMethod <string>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <string> action = (Func <string>)test;

            Assert.Equal(string.Empty, action());

            //测试string 有临时变量
            Delegate test2 = EHandler.CreateMethod <string>((il) =>
            {
                EVar temp_var = EVar.CreateVarFromObject(string.Empty);
                EMethod.Load(typeof(Console)).ExecuteMethod <string>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <string> action2 = (Func <string>)test2;

            Assert.Equal(string.Empty, action2());
        }