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

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

            Assert.AreSame(reader1, reader2);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }