public void PropertyBagTwoWayObjectSerializationTest() { var bag = new PropertyBag(); bag.Add("key", "Value"); bag.Add("Key2", 100.10M); bag.Add("Key3", Guid.NewGuid()); bag.Add("Key4", DateTime.Now); bag.Add("Key5", true); bag.Add("Key7", new byte[3] { 42, 45, 66 }); bag.Add("Key8", null); bag.Add("Key9", new ComplexObject() { Name = "Rick", Entered = DateTime.Now, Count = 10 }); string xml = bag.ToXml(); TestContext.WriteLine(bag.ToXml()); bag.Clear(); bag.FromXml(xml); Assert.IsTrue(bag["key"] as string == "Value"); Assert.IsInstanceOfType(bag["Key3"], typeof(Guid)); Assert.IsNull(bag["Key8"]); //Assert.IsNull(bag["Key10"]); Assert.IsInstanceOfType(bag["Key9"], typeof(ComplexObject)); }
public void PropertyBagTwoWayValueTypeSerializationTest() { var bag = new PropertyBag <decimal>(); bag.Add("key", 10M); bag.Add("Key1", 100.10M); bag.Add("Key2", 200.10M); bag.Add("Key3", 300.10M); string xml = bag.ToXml(); TestContext.WriteLine(bag.ToXml()); bag.Clear(); bag.FromXml(xml); Assert.IsTrue(bag["Key1"] == 100.10M); Assert.IsTrue(bag["Key3"] == 300.10M); }
/// <summary> /// Loads the Properties dictionary with values from a Properties property of /// an entity object. Once loaded you can access the dictionary to read and write /// values from it arbitrarily and use SetProperties to write the values back /// in serialized form to the underlying property for database storage. /// </summary> /// <param name="stringFieldNameToLoadFrom">The name of the field to load the XML properties from.</param> protected void GetProperties(string stringFieldNameToLoadFrom = "Properties", object entity = null) { Properties = null; if (entity == null) { entity = Entity; } // Always create a new property bag Properties = new PropertyBag(); string fieldValue = ReflectionUtils.GetProperty(entity, stringFieldNameToLoadFrom) as string; if (string.IsNullOrEmpty(fieldValue)) { return; } // load up Properties from XML Properties.FromXml(fieldValue); }
public void PropertyBagTwoWayObjectSerializationTest() { var bag = new PropertyBag(); bag.Add("key", "Value"); bag.Add("Key2", 100.10M); bag.Add("Key3", Guid.NewGuid()); bag.Add("Key4", DateTime.Now); bag.Add("Key5", true); bag.Add("Key7", new byte[3] { 42, 45, 66 } ); bag.Add("Key8", null); bag.Add("Key9", new ComplexObject() { Name = "Rick", Entered = DateTime.Now, Count = 10 }); string xml = bag.ToXml(); TestContext.WriteLine(bag.ToXml()); bag.Clear(); bag.FromXml(xml); Assert.IsTrue(bag["key"] as string == "Value"); Assert.IsInstanceOfType( bag["Key3"], typeof(Guid)); Assert.IsNull(bag["Key8"]); //Assert.IsNull(bag["Key10"]); Assert.IsInstanceOfType(bag["Key9"], typeof(ComplexObject)); }
public void PropertyBagTwoWayValueTypeSerializationTest() { var bag = new PropertyBag<decimal>(); bag.Add("key", 10M); bag.Add("Key1", 100.10M); bag.Add("Key2", 200.10M); bag.Add("Key3", 300.10M); string xml = bag.ToXml(); TestContext.WriteLine(bag.ToXml()); bag.Clear(); bag.FromXml(xml); Assert.IsTrue(bag["Key1"] == 100.10M); Assert.IsTrue(bag["Key3"] == 300.10M); }
/// <summary> /// Loads the Properties dictionary with values from a Properties property of /// an item object. Once loaded you can access the dictionary to read and write /// values from it arbitrarily and use SetProperties to write the values back /// in serialized form to the underlying property for database storage. /// </summary> /// <param name="stringFieldNameToLoadFrom">The name of the field to load the XML properties from.</param> protected void GetProperties(string stringFieldNameToLoadFrom = "Properties", object entity = null) { Properties = null; if (entity == null) entity = Item; // Always create a new property bag Properties = new PropertyBag(); string fieldValue = ReflectionUtils.GetProperty(entity, stringFieldNameToLoadFrom) as string; if (string.IsNullOrEmpty(fieldValue)) return; // load up Properties from XML Properties.FromXml(fieldValue); }