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); }
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); }
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); }
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); }
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); }
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; }
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()); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }