Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public static void TestEReflector()
        {
            EReflector.Create(typeof(TestStruct));
            TestStruct t2 = new TestStruct();

            t2.Name = "值引用类型不吃Set这套,因为它不是ref引用";
            EReflector.SetMethodDict[typeof(TestStruct)]["Name"](t2, "小明1");
            EReflector.SetMethodDict[typeof(TestStruct)]["Age"](t2, 11);
            EReflector.SetMethodDict[typeof(TestStruct)]["Age1"](t2, 22);
            EReflector.SetMethodDict[typeof(TestStruct)]["Name1"](t2, "小明2");
            Console.WriteLine(EReflector.GetMethodDict[typeof(TestStruct)]["Name"](t2));
            Console.WriteLine(EReflector.GetMethodDict[typeof(TestStruct)]["Age"](t2));
            Console.WriteLine(EReflector.GetMethodDict[typeof(TestStruct)]["Name1"](t2));
            Console.WriteLine(EReflector.GetMethodDict[typeof(TestStruct)]["Age1"](t2));
            EReflector.Create(typeof(TestClass));
            TestClass t3 = new TestClass();

            t3.Age       = 1;
            t3.FieldNext = new TestStruct()
            {
                Age = 1
            };
            TestStruct t = (TestStruct)(EReflector.GetMethodDict[typeof(TestClass)]["FieldNext"](t3));

            Console.WriteLine(t.Age);
        }