Example #1
0
        public static void TestStructClone()
        {
            EReflector.Create(typeof(SingleModel));
            TestStruct t = new TestStruct();

            t.TEnum = TestEnum.Address;
            t.Set();
            t.Name  = "小明";
            t.Name1 = "小明1";
            t.Age   = 10;
            t.Age1  = 101;

            Delegate ShowDelegate = EHandler.CreateMethod <TestStruct>((il) =>
            {
                EMethod methodInfoHelper = typeof(Console);
                EModel model             = EModel.CreateModelFromObject(t);
                model.SField("PrivateFAge", 10);
                model.LFieldValue("PrivateFAge");
                methodInfoHelper.ExecuteMethod <int>("WriteLine");
                model.Load();
            }).Compile();
            TestStruct t2 = ((Func <TestStruct>)ShowDelegate)();

            Console.WriteLine(t2.Name);
            Console.WriteLine(t2.Age);
            Console.WriteLine(t2.Name1);
            Console.WriteLine(t2.Age1);
            t2.Show();
            Console.WriteLine(t.TEnum);
            Console.WriteLine(t2.TEnum);
        }
Example #2
0
        public void TestClass()
        {
            ComplexClassModel model = new ComplexClassModel();

            model.FieldModel        = new FieldStruct();
            model.PropertyModel     = new PropertyStruct();
            model.MethodModel       = new MethodStruct();
            ComplexClassModel.Model = model;

            Delegate test = EHandler.CreateMethod <ComplexClassModel>((il) =>
            {
                EVar ulongMinHandler = ulong.MinValue;
                EModel modelHandler  = EModel.CreateModelFromObject(model);
                modelHandler.Load("FieldModel").Set("RefField", "Hello");
                modelHandler.Load("PropertyModel").Set("RefProperty", "Hello");
                modelHandler.Load("PropertyModel").Set("ValueProperty", ulongMinHandler);
                modelHandler.Load("Model").Load("FieldModel").Set("RefField", "Hello1");
                modelHandler.Load("Model").Load("FieldModel").Set("ValueField", () => { EMethod.Load(modelHandler.DLoad("MethodModel").Operator).ExecuteMethod("GetULongMax"); });
                modelHandler.Load();
            }).Compile();
            Func <ComplexClassModel> action = (Func <ComplexClassModel>)test;
            ComplexClassModel        result = action();

            Assert.Equal((ulong)0, result.FieldModel.ValueField);
            Assert.Equal(ulong.MinValue, result.PropertyModel.ValueProperty);
            Assert.Equal("Hello", result.FieldModel.RefField);
            Assert.Equal("Hello", result.PropertyModel.RefProperty);
            Assert.Equal(ulong.MaxValue, ComplexClassModel.Model.FieldModel.ValueField);
            Assert.Equal("Hello1", ComplexClassModel.Model.FieldModel.RefField);
            //Assert.Equal("Hello1", model.FieldModel.RefField);
        }
Example #3
0
        public void TestProperty()
        {
            PropertyStruct model = new PropertyStruct();

            model.ValueProperty = 100;
            model.RefProperty   = "Test";
            PropertyStruct.StaticRefProeprty   = "Static";
            PropertyStruct.StaticValueProperty = 200;
            Delegate test = EHandler.CreateMethod <PropertyStruct>((il) =>
            {
                EModel modelHandler = EModel.CreateModelFromObject(model);
                modelHandler.Set("ValueProperty", modelHandler.DLoad("ValueProperty").Operator + modelHandler.DLoad("StaticValueProperty").DelayAction);
                modelHandler.Set("StaticValueProperty", modelHandler.DLoad("ValueProperty").Operator + modelHandler.DLoad("StaticValueProperty").DelayAction);
                modelHandler.Set("RefProperty", modelHandler.DLoad("RefProperty").Operator + modelHandler.DLoad("StaticRefProeprty").DelayAction);
                modelHandler.Load();
            }).Compile();
            Func <PropertyStruct> action = (Func <PropertyStruct>)test;

            PropertyStruct.StaticValueProperty = 200;
            PropertyStruct result = action();

            Assert.Equal((ulong)300, result.ValueProperty);
            Assert.Equal((ulong)500, PropertyStruct.StaticValueProperty);
            Assert.Equal("TestStatic", result.RefProperty);
        }
Example #4
0
        public void TestProperty()
        {
            ClassWithNullableModel model = new ClassWithNullableModel();

            model.ValueField    = 100;
            model.ValueProperty = null;
            ClassWithNullableModel.StaticValueField    = null;
            ClassWithNullableModel.StaticValueProperty = 200;
            Delegate test = EHandler.CreateMethod <ClassWithNullableModel>((il) =>
            {
                EModel modelHandler = EModel.CreateModelFromObject(model);

                modelHandler.Set("ValueProperty", modelHandler.DLoad("PrivateProperty").DLoad("Value").Operator + modelHandler.DLoad("StaticValueProperty").DLoad("Value").Operator);
                modelHandler.Set("ValueProperty", modelHandler.DLoad("PrivateProperty").DLoad("Value").Operator + modelHandler.DLoad("StaticValueProperty").DLoad("Value").Operator);
                modelHandler.Set("StaticValueProperty", modelHandler.DLoad("ValueProperty").DLoad("Value").Operator + modelHandler.DLoad("StaticValueProperty").DLoad("Value").Operator);
                modelHandler.Set("ValueField", modelHandler.DLoad("StaticValueProperty").DLoad("Value").Operator + modelHandler.DLoad("ValueField").DLoad("Value").Operator);
                modelHandler.Load();
            }).Compile();
            Func <ClassWithNullableModel> action = (Func <ClassWithNullableModel>)test;
            ClassWithNullableModel        result = action();

            Assert.Equal((ulong)201, result.ValueProperty);
            Assert.Equal((ulong)401, ClassWithNullableModel.StaticValueProperty);
            Assert.Equal((ulong)501, result.ValueField);
        }
Example #5
0
        public static void TestClassClone()
        {
            SingleModel t = new SingleModel();

            t.TestStructArray    = new TestStruct[5];
            t.TestStructArray[3] = new TestStruct {
                Age = 666
            };
            t.TestClassArray     = new TestClass[15];
            t.TestClassArray[10] = new TestClass()
            {
                Name = "xxxx"
            };
            t.TestEnumArray     = new TestEnum[16];
            t.TestEnumArray[15] = TestEnum.Address;
            t.Name = "小明";
            t.Age  = 10;
            t.Set();
            Delegate ShowDelegate = EHandler.CreateMethod <SingleModel>((il) =>
            {
                EModel model = EModel.CreateModelFromObject(t);
                model.Load();
            }).Compile();
            SingleModel t2 = ((Func <SingleModel>)ShowDelegate)();

            Console.WriteLine(t2.Name);
            Console.WriteLine(t2.Age);
            t2.Show();
            Console.WriteLine(t2.TestStructArray[3].Age);
            Console.WriteLine(t2.TestClassArray[10].Name);
            Console.WriteLine(t2.TestEnumArray[15]);
        }
Example #6
0
        public static void T <T>()
        {
            ClassWithNullableModel model = new ClassWithNullableModel();

            model.ValueField    = 100;
            model.ValueProperty = null;
            ClassWithNullableModel.StaticValueField    = 100;
            ClassWithNullableModel.StaticValueProperty = 200;
            Delegate test = EHandler.CreateMethod <ClassWithNullableModel>((il) =>
            {
                EModel modelHandler = EModel.CreateModelFromObject(model);
                //EModel modelHandler = EModel.CreateModel<ClassWithNullableModel>().UseDefaultConstructor();
                //modelHandler.Set("<ValueProperty>k__BackingField", (ulong)100);
                //modelHandler.Set("ValueField", (ulong)100);
                //modelHandler.Set("StaticValueField", (ulong)100);
                //modelHandler.Set("ValueProperty", (ulong)100);
                //modelHandler.Set("<StaticValueProperty>k__BackingField", (ulong)300);
                //modelHandler.LoadValue("<ValueProperty>k__BackingField").Packet();
                //FieldInfo info = typeof(ClassWithNullableModel).GetField("<PrivateProperty>k__BackingField", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                //il.REmit(OpCodes.Ldtoken, typeof(ClassWithNullableModel));
                //il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                //il.REmit(OpCodes.Ldstr, "<PrivateProperty>k__BackingField");
                //il.REmit(OpCodes.Ldc_I4_S, 60);
                //il.REmit(OpCodes.Callvirt, ClassCache.FieldInfoGetter);
                //LocalBuilder field = il.DeclareLocal(typeof(FieldInfo));
                //il.REmit(OpCodes.Stloc_S, field.LocalIndex);
                //il.LoadBuilder(field);
                ////il.REmit(OpCodes.Callvirt, ClassCache.FieldInfoGetter);
                //modelHandler.InStackAndPacket();
                //il.REmit(OpCodes.Callvirt, ClassCache.FieldValueGetter);
                //, modelHandler.DLoad("PrivateProperty").DLoad("Value").DelayAction
                //modelHandler.Load("<PrivateProperty>k__BackingField").LoadValue("value");
                //EMethod.Load(typeof(Console)).ExecuteMethod<ulong>("WriteLine");
                //modelHandler.Set("ValueProperty", modelHandler.DLoad("PrivateProperty").DLoad("Value").DelayAction);
                //EMethod.Load(typeof(Console)).ExecuteMethod<ulong>("WriteLine", modelHandler.DLoad("ValueProperty").DLoad("Value").DelayAction);
                //EMethod.Load(typeof(Console)).ExecuteMethod<ulong>("WriteLine", modelHandler.DLoad("PrivateProperty").DLoad("Value").DelayAction);
                //modelHandler.LoadValue("ValueField").Packet();
                //EMethod.Load(typeof(Console)).ExecuteMethod<object>("WriteLine");
                //modelHandler.LoadValue("ValueProperty").Packet();
                //EMethod.Load(typeof(Console)).ExecuteMethod<object>("WriteLine");
                //modelHandler.LoadValue("StaticValueField").Packet();
                //EMethod.Load(typeof(Console)).ExecuteMethod<object>("WriteLine");
                //modelHandler.LoadValue("StaticValueProperty").Packet();
                //EMethod.Load(typeof(Console)).ExecuteMethod<object>("WriteLine");

                //EMethod.Load(typeof(Console)).ExecuteMethod<ulong>("WriteLine", modelHandler.DLoad("ValueField").DelayAction);
                //EMethod.Load(typeof(Console)).ExecuteMethod<object>("WriteLine", modelHandler.DLoad("StaticValueProperty").DelayAction);
                //modelHandler.Set("ValueProperty", modelHandler.DLoad("ValueProperty").Operator + modelHandler.DLoad("StaticValueProperty").DelayAction);
                //modelHandler.Set("StaticValueProperty", modelHandler.DLoad("ValueProperty").Operator + modelHandler.DLoad("StaticValueProperty").DelayAction);
                // modelHandler.Set("RefProperty", modelHandler.DLoad("RefProperty").Operator + modelHandler.DLoad("StaticRefProeprty").DelayAction);
                modelHandler.Load();
            }).Compile();
            Func <ClassWithNullableModel> action1 = (Func <ClassWithNullableModel>)test;
            ClassWithNullableModel        t       = action1();
        }
Example #7
0
 public EModel GetAttributeModel(string attributeName)
 {
     attributeName += "Attribute";
     if (Struction.AttributeTree.ContainsKey(MemberName))
     {
         if (Struction.AttributeTree[MemberName].ContainsKey(attributeName))
         {
             object value = Struction.AttributeTree[MemberName][attributeName];
             return(EModel.CreateModelFromObject(value, value.GetType()));
         }
     }
     return(null);
 }
Example #8
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 #9
0
        public static void TestDictionaryClone()
        {
            Dictionary <int, string> testList = new Dictionary <int, string>();

            testList[0] = "One";
            testList[1] = "Two";
            testList[2] = "Three";
            Delegate ShowDelegate = EHandler.CreateMethod <Dictionary <int, string> >((il) =>
            {
                EModel model = EModel.CreateModelFromObject(testList);
                model.Load();
            }).Compile();
            Dictionary <int, string> t2 = ((Func <Dictionary <int, string> >)ShowDelegate)();

            testList.Remove(0);
            Console.WriteLine(testList[0]);
            Console.WriteLine(t2[0]);
        }
Example #10
0
        public static void TestListClone()
        {
            List <string> testList = new List <string>();

            testList.Add("One");
            testList.Add("Two");
            testList.Add("Three");
            Delegate ShowDelegate = EHandler.CreateMethod <List <string> >((il) =>
            {
                EModel model = EModel.CreateModelFromObject(testList);
                model.Load();
            }).Compile();
            List <string> t2 = ((Func <List <string> >)ShowDelegate)();

            testList.RemoveAt(0);
            Console.WriteLine(testList[0]);
            Console.WriteLine(t2[0]);
        }
Example #11
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 #12
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 #13
0
        public static void Main()
        {
            FieldClass model = new FieldClass();

            model.ValueField            = 100;
            model.RefField              = "Test";
            FieldClass.StaticRefField   = "Static";
            FieldClass.StaticValueField = 200;
            Delegate test = EHandler.CreateMethod <FieldClass>((il) =>
            {
                EModel modelHandler = EModel.CreateModelFromObject(model);
                modelHandler.Set("ValueField", modelHandler.DLoad("ValueField").Operator + modelHandler.DLoad("StaticValueField").DelayAction);
                //modelHandler.Set("StaticValueField", modelHandler.DLoadValue("ValueField").Operator + modelHandler.DLoadValue("StaticValueField").DelayAction);
                //modelHandler.Set("RefField", modelHandler.DLoadValue("RefField").Operator + modelHandler.DLoadValue("StaticRefField").DelayAction);
                modelHandler.Load();
            }).Compile();
            Func <FieldClass> action = (Func <FieldClass>)test;
            FieldClass        result = action();
        }
Example #14
0
        public void TestField()
        {
            FieldClass model = new FieldClass();

            model.ValueField            = ulong.MaxValue;
            model.RefField              = "Test";
            FieldClass.StaticRefField   = "Static";
            FieldClass.StaticValueField = ulong.MinValue;
            Delegate test = EHandler.CreateMethod <FieldClass>((il) =>
            {
                EModel modelHandler = EModel.CreateModelFromObject(model);
                modelHandler.Set("ValueField", ulong.MaxValue);
                modelHandler.Set("StaticValueField", ulong.MinValue);
                modelHandler.Set("RefField", modelHandler.DLoadValue("RefField").Operator + modelHandler.DLoadValue("StaticRefField").DelayAction);
                modelHandler.Load();
            }).Compile();
            Func <FieldClass> action = (Func <FieldClass>)test;
            FieldClass        result = action();

            Assert.Equal(ulong.MaxValue, result.ValueField);
            Assert.Equal(ulong.MinValue, FieldClass.StaticValueField);
            Assert.Equal("TestStatic", result.RefField);
        }
Example #15
0
        public void TestField()
        {
            FieldStruct model = new FieldStruct();

            model.ValueField             = 100;
            model.RefField               = "Test";
            FieldStruct.StaticRefField   = "Static";
            FieldStruct.StaticValueField = 200;
            Delegate test = EHandler.CreateMethod <FieldStruct>((il) =>
            {
                EModel modelHandler = EModel.CreateModelFromObject(model);
                modelHandler.Set("ValueField", modelHandler.DLoadValue("ValueField").Operator + modelHandler.DLoadValue("StaticValueField").DelayAction);
                modelHandler.Set("StaticValueField", modelHandler.DLoadValue("ValueField").Operator + modelHandler.DLoadValue("StaticValueField").DelayAction);
                modelHandler.Set("RefField", modelHandler.DLoadValue("RefField").Operator + modelHandler.DLoadValue("StaticRefField").DelayAction);
                modelHandler.Load();
            }).Compile();
            Func <FieldStruct> action = (Func <FieldStruct>)test;
            FieldStruct        result = action();

            Assert.Equal((ulong)300, result.ValueField);
            Assert.Equal((ulong)500, FieldStruct.StaticValueField);
            Assert.Equal("TestStatic", result.RefField);
        }
Example #16
0
        public void TestProperty()
        {
            PropertyClass model = new PropertyClass();

            model.ValueProperty               = ulong.MaxValue;
            model.RefProperty                 = "Test";
            PropertyClass.StaticRefProeprty   = "Static";
            PropertyClass.StaticValueProperty = ulong.MinValue;
            Delegate test = EHandler.CreateMethod <PropertyClass>((il) =>
            {
                EModel modelHandler = EModel.CreateModelFromObject(model);
                modelHandler.Set("ValueProperty", ulong.MaxValue);
                modelHandler.Set("StaticValueProperty", ulong.MinValue);
                modelHandler.Set("RefProperty", modelHandler.DLoad("RefProperty").Operator + modelHandler.DLoad("StaticRefProeprty").DelayAction);
                modelHandler.Load();
            }).Compile();
            Func <PropertyClass> action = (Func <PropertyClass>)test;
            PropertyClass        result = action();

            Assert.Equal(ulong.MaxValue, result.ValueProperty);
            Assert.Equal(ulong.MinValue, PropertyClass.StaticValueProperty);
            Assert.Equal("TestStatic", result.RefProperty);
        }
Example #17
0
        public static void TestComplexClone()
        {
            TestClass testModel = new TestClass();

            testModel.Name = "X";
            testModel.Age  = 10;

            TestStruct nestingStruct = new TestStruct();

            nestingStruct.Age  = 101;
            nestingStruct.Name = "CX";

            TestInterfaceModel interfaceModel = new TestInterfaceModel();

            interfaceModel.Shut = true;

            testModel.PInterface    = interfaceModel;
            testModel.FieldNext     = nestingStruct;
            testModel.PropertyNext1 = nestingStruct;

            Delegate ShowDelegate = EHandler.CreateMethod <TestClass>((il) =>
            {
                EMethod method    = typeof(Console);
                EModel classModel = EModel.CreateModelFromObject(testModel);
                classModel.ALoad("PrivatePName").GetAttributeModel("Attribute1").LoadValue("Name");
                method.ExecuteMethod <string>("WriteLine");
                classModel.Load();
            }).Compile();
            TestClass Result = ((Func <TestClass>)ShowDelegate)();

            Console.WriteLine(Result.Name);
            Console.WriteLine(Result.FieldNext.Name);
            Console.WriteLine(Result.FieldNext.Age);
            Console.WriteLine(Result.PropertyNext1.Name);
            Console.WriteLine(Result.PropertyNext1.Age);
            Console.WriteLine(Result.PInterface.Shut);
        }
Example #18
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 #19
0
        public static void NoErrorLoad(this ILGenerator il, object value)
        {
            ENull enull = value as ENull;

            if (value != null)
            {
                Type          type          = value.GetType();
                ILoadInstance instance      = value as ILoadInstance;
                LocalBuilder  builder       = value as LocalBuilder;
                IOperator     modelOperator = value as IOperator;
                if (value is Action)
                {
                    ((Action)value)();
                }
                else if (instance != null)
                {
                    instance.Load();
                }
                else if (builder != null)
                {
                    il.EmitLoadBuidler(builder);
                }
                else if (enull != null)
                {
                    il.REmit(OpCodes.Ldnull);
                }
                else if (value is Type)
                {
                    il.REmit(OpCodes.Ldtoken, (Type)value);
                    il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                }
                else if (type.IsClass && type != typeof(string))
                {
                    EModel model = EModel.CreateModelFromObject(value, type);
                    model.Load();
                }
                else if (type.IsEnum)
                {
                    il.REmit(OpCodes.Ldc_I4, (int)value);
                }
                else if (type.IsValueType && !type.IsPrimitive)
                {
                    EModel model;
                    if (EStruckCheck.IsDefaultStruct(value, type))
                    {
                        model = EModel.CreateModel(type);
                    }
                    else
                    {
                        model = EModel.CreateModelFromObject(value, type);
                    }
                    model.Load();
                }
                else
                {
                    il.LoadObject(value, type);
                    //il.CallNullableCtor(type);
                }
            }
            else
            {
                il.REmit(OpCodes.Ldnull);
            }
        }