public void ShouldSetPropertyValue() { var targetType = typeof(SampleClassWithInjectionProperties); var targetProperty = targetType.GetProperty("SomeProperty"); Assert.IsNotNull(targetProperty); // Configure the target var instance = new SampleClassWithInjectionProperties(); // This is the service that should be assigned // to the SomeProperty property object service = new SampleClass(); // Initialize the container var container = new ServiceContainer(); container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "LinFu*.dll"); IPropertySetter setter = container.GetService <IPropertySetter>(); Assert.IsNotNull(setter); setter.Set(instance, targetProperty, service); Assert.IsNotNull(instance.SomeProperty); Assert.AreSame(service, instance.SomeProperty); }
public void SetValue(string name, string propertyName, object value, IPropertySetter setter) { if (DBNull.Value.Equals(value)) { value = null; } if (setter != null) { setter.Set(this.store[name].DataObject, value); return; } PropertyInfo property = this.store[name].Type.GetProperty(propertyName); object value2 = LanguagePrimitives.ConvertTo(value, property.PropertyType); property.SetValue(this.store[name].DataObject, value2, null); }