public PropertyBag Convert(object obj) { Type type = obj.GetType(); var document = new PropertyBag(type); foreach (PropertyInfo propertyInfo in type.GetProperties(PublicInstanceProperties)) { document.AddPropertyValue(propertyInfo.Name, propertyInfo.GetValue(obj, null)); } return document; }
public void Restoration_of_an_event_from_a_property_bag_containing_nulls_should_not_fail() { try { var converter = new PropertyBagConverter { TypeResolver = new SimpleEventTypeResolver() }; var bag = new PropertyBag(typeof(TestEvent).AssemblyQualifiedName); bag.AddPropertyValue("SomeString", null); var obj = converter.Convert(bag); obj.Should().NotBeNull(); obj.Should().BeOfType<TestEvent>(); ((TestEvent) obj).SomeString.Should().BeNull(); } catch(Exception e) { Assert.Fail(e.ToString()); } }