示例#1
0
        public void PropertySetMethodDelegateCacheTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            var writer1 = (Func <object, int, int>)DynamicHelper.GetPropertySetterDelegate(typeof(PropertyTestObject).GetProperty("PrivateInt", BindingFlags.Instance | BindingFlags.NonPublic));
            var writer2 = (Func <object, int, int>)DynamicHelper.GetPropertySetterDelegate(typeof(PropertyTestObject).GetProperty("PrivateInt", BindingFlags.Instance | BindingFlags.NonPublic));

            Assert.AreSame(writer1, writer2);
        }
示例#2
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);
        }
示例#3
0
        public void FieldGetMethodDelegateCacheTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            Func <object, object> reader1 = (Func <object, object>)DynamicHelper.GetFiledGetterDelegate(typeof(PropertyTestObject).GetField("PublicField"), typeof(object));
            Func <object, object> reader2 = (Func <object, object>)DynamicHelper.GetFiledGetterDelegate(typeof(PropertyTestObject).GetField("PublicField"), typeof(object));

            Assert.AreSame(reader1, reader2);
        }
示例#4
0
        public void MethodDelegateCacheTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            Func <object, int, int, int> func1 = (Func <object, int, int, int>)DynamicHelper.GetMethodInvokeDelegate(data.GetType().GetMethod("Add"));

            Func <object, int, int, int> func2 = (Func <object, int, int, int>)DynamicHelper.GetMethodInvokeDelegate(data.GetType().GetMethod("Add"));

            Assert.AreSame(func1, func2);
        }
示例#5
0
        public void InvokePublicMethodTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            Func <object, int, int, int> func = (Func <object, int, int, int>)DynamicHelper.GetMethodInvokeDelegate(data.GetType().GetMethod("Add"));

            int result = func(data, 3, 4);

            Assert.AreEqual(7, result);
        }
示例#6
0
        public static PropertyTestObject PrepareTestData()
        {
            PropertyTestObject data = new PropertyTestObject();

            data.ID         = UuidHelper.NewUuidString();
            data.User       = TestUser.PrepareTestData();
            data.PrivateInt = 1024;

            return(data);
        }
        public static PropertyTestObject PrepareTestData()
        {
            PropertyTestObject data = new PropertyTestObject();

            data.ID = UuidHelper.NewUuidString();
            data.User = TestUser.PrepareTestData();
            data.PrivateInt = 1024;

            return data;
        }
示例#8
0
        public void PrivatePropertySetTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            var writer = (Func <object, int, int>)DynamicHelper.GetPropertySetterDelegate(typeof(PropertyTestObject).GetProperty("PrivateInt", BindingFlags.Instance | BindingFlags.NonPublic));

            writer(data, 2048);

            Assert.AreEqual(2048, data.GetPrivateInt());
        }
示例#9
0
        public void PrivatePropertyGetTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            Func <object, int> reader = (Func <object, int>)DynamicHelper.GetPropertyGetterDelegate(typeof(PropertyTestObject).GetProperty("PrivateInt", BindingFlags.Instance | BindingFlags.NonPublic));

            int dataRead = (int)reader(data);

            Assert.AreEqual(data.GetPrivateInt(), dataRead);
        }
示例#10
0
        public void InterfacePropertySetNullTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            var writer = (Func <object, IUser, IUser>)DynamicHelper.GetPropertySetterDelegate(typeof(PropertyTestObject).GetProperty("User"));

            writer(data, null);

            Assert.IsNull(data.User);
        }
示例#11
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);
        }
示例#12
0
        public void InterfacePropertySetUserTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            var writer = (Func <object, IUser, IUser>)DynamicHelper.GetPropertySetterDelegate(typeof(PropertyTestObject).GetProperty("User"));

            IUser user = TestUser.PrepareTestData();

            writer(data, user);

            Assert.AreSame(data.User, user);
        }
示例#13
0
        public void InterfacePropertyGetTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            IUser originalUser = data.User;

            Func <object, IUser> reader = (Func <object, IUser>)DynamicHelper.GetPropertyGetterDelegate(typeof(PropertyTestObject).GetProperty("User"));

            IUser userRead = reader(data);

            Assert.AreSame(originalUser, userRead);
        }
示例#14
0
        public void SimplePropertyGetTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            string originalID = data.ID;

            Func <object, string> reader = (Func <object, string>)DynamicHelper.GetPropertyGetterDelegate(typeof(PropertyTestObject).GetProperty("ID"));

            string idRead = reader(data);

            Assert.AreEqual(originalID, idRead);
        }
示例#15
0
        public void SimpleFieldGetTest()
        {
            PropertyTestObject data = PropertyTestObject.PrepareTestData();

            string originalValue = data.PublicField;

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

            string idRead = reader(data);

            Assert.AreEqual(originalValue, idRead);
        }