本文整理汇总了C#中PropertyBag.FromXml方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyBag.FromXml方法的具体用法?C# PropertyBag.FromXml怎么用?C# PropertyBag.FromXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyBag
的用法示例。
在下文中一共展示了PropertyBag.FromXml方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PropertyBagTwoWayValueTypeSerializationTest
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);
}
示例2: PropertyBagTwoWayObjectSerializationTest
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));
}
示例3: GetProperties
/// <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);
}