public void SetterFuncCached() { var reflectionCache = new ReflectionCache(); var propertyInfo = typeof(Foo).GetProperty(nameof(Foo.Property1)); var func = reflectionCache.GetPropertySetter(propertyInfo); Assert.IsNotNull(func); var func2 = reflectionCache.GetPropertySetter(propertyInfo); Assert.IsNotNull(func2); Assert.AreEqual(func, func2); }
public void GetPropertyFuncGenericAndSetValue() { var reflectionCache = new ReflectionCache(); var propertyInfo = typeof(Foo).GetProperty(nameof(Foo.Property1)); foreach (DelegateCreationMode mode in delegateCreationModes) { InvokeUsingMode(mode); } void InvokeUsingMode(DelegateCreationMode mode) { var func = reflectionCache.GetPropertySetter <string>(propertyInfo, mode); Assert.IsNotNull(func, mode.ToString()); var foo = new Foo(); const string expectedValue1 = "Foo"; func(foo, expectedValue1); Assert.AreEqual(expectedValue1, foo.Property1, mode.ToString()); } }
public void SetterFuncCachedGeneric() { var reflectionCache = new ReflectionCache(); var propertyInfo = typeof(Foo).GetProperty(nameof(Foo.Property1)); foreach (DelegateCreationMode mode in delegateCreationModes) { InvokeUsingMode(mode); } void InvokeUsingMode(DelegateCreationMode mode) { var func = reflectionCache.GetPropertySetter <string>(propertyInfo, mode); Assert.IsNotNull(func, mode.ToString()); var func2 = reflectionCache.GetPropertySetter <string>(propertyInfo, mode); Assert.IsNotNull(func2, mode.ToString()); Assert.AreEqual(func, func2, mode.ToString()); } }
public void GetPropertyFuncGenericAndSetValue() { var reflectionCache = new ReflectionCache(); var propertyInfo = typeof(Foo).GetProperty(nameof(Foo.Property1)); var func = reflectionCache.GetPropertySetter <string>(propertyInfo); Assert.IsNotNull(func); var foo = new Foo(); const string expectedValue1 = "Foo"; func(foo, expectedValue1); Assert.AreEqual(expectedValue1, foo.Property1); }