Esempio n. 1
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());
        }
Esempio n. 2
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());
        }
Esempio n. 3
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());
        }
Esempio n. 4
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());
        }
Esempio n. 5
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());
        }
Esempio n. 6
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());
        }
Esempio n. 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());
        }
Esempio n. 8
0
        public void TestInt()
        {
            int[]    testArray    = new int[] { 1, 2, 3, 4, 5 };
            Delegate ShowDelegate = EHandler.CreateMethod <int>((il) =>
            {
                EVar result  = EVar.CreateVar <int>();
                EArray Model = testArray;
                ELoop.For(Model, (loadCurrentElement) =>
                {
                    result.Store(result + loadCurrentElement);
                });
                result.Load();
            }).Compile();

            Assert.Equal(15, ((Func <int>)ShowDelegate)());
        }
Esempio n. 9
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();
        }
Esempio n. 10
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)();
        }