예제 #1
0
        public void FieldSetMethodDelegateCacheTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            Func <object, string, string> writer1 = (Func <object, string, string>)DynamicHelper.GetFieldSetterDelegate(typeof(PropertyTestObject).GetField("PublicField"));
            Func <object, string, string> writer2 = (Func <object, string, string>)DynamicHelper.GetFieldSetterDelegate(typeof(PropertyTestObject).GetField("PublicField"));

            Assert.AreSame(writer1, writer2);
        }
예제 #2
0
        public void SimpleFieldSetTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            Func <object, string, string> writer = (Func <object, string, string>)DynamicHelper.GetFieldSetterDelegate(typeof(PropertyTestObject).GetField("PublicField"));

            writer(data, "新字段值");

            Assert.AreEqual("新字段值", data.PublicField);
        }