本文整理汇总了C#中PropertyBag.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyBag.SetValue方法的具体用法?C# PropertyBag.SetValue怎么用?C# PropertyBag.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyBag
的用法示例。
在下文中一共展示了PropertyBag.SetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializationDoubleRoundtrip
public void SerializationDoubleRoundtrip ()
{
var bag = new PropertyBag ();
var t = new SerializableObject {
SomeValue = "test1"
};
bag.SetValue ("foo", t);
var w = new StringWriter ();
var ser = new XmlDataSerializer (new DataContext ());
ser.Serialize (w, bag);
var data = w.ToString ();
SerializableObject.CreationCount = 0;
bag = ser.Deserialize<PropertyBag> (new StringReader (data));
// SerializableObject is not instantiated if not queried
Assert.AreEqual (0, SerializableObject.CreationCount);
w = new StringWriter ();
ser.Serialize (w, bag);
data = w.ToString ();
bag = ser.Deserialize<PropertyBag> (new StringReader (data));
// SerializableObject is not instantiated if not queried
Assert.AreEqual (0, SerializableObject.CreationCount);
t = bag.GetValue<SerializableObject> ("foo");
Assert.NotNull (t);
Assert.AreEqual ("test1", t.SomeValue);
}
示例2: ShouldProvideFluentInterfaceForBuildingMetadata
public void ShouldProvideFluentInterfaceForBuildingMetadata()
{
PropertyBag extraMetadata = new PropertyBag();
extraMetadata.SetValue("Author", "Lewis Carroll");
extraMetadata.SetValue("Title", "The Jabberwocky");
DataRow row = new DataRow("abc")
.WithMetadata("Description", "Frumious")
.WithMetadata("Name", "Bandersnatch")
.WithMetadata(extraMetadata);
Assert.AreEqual("abc", row.GetValue(new DataBinding(0, null)));
PropertyBag map = DataItemUtils.GetMetadata(row);
Assert.Count(4, map);
Assert.AreEqual("Frumious", map.GetValue("Description"));
Assert.AreEqual("Bandersnatch", map.GetValue("Name"));
Assert.AreEqual("Lewis Carroll", map.GetValue("Author"));
Assert.AreEqual("The Jabberwocky", map.GetValue("Title"));
}
示例3: GetAndSetValue
public void GetAndSetValue()
{
PropertyBag bag = new PropertyBag();
Assert.IsNull(bag.GetValue("key"));
bag.SetValue("key", "value");
Assert.AreEqual("value", bag.GetValue("key"));
bag.SetValue("key", "different value");
Assert.AreEqual("different value", bag.GetValue("key"));
bag.SetValue("key", null);
Assert.IsNull(bag.GetValue("key"));
bag.Add("key", "value1");
bag.Add("key", "value2");
Assert.AreEqual("value1", bag.GetValue("key"));
Assert.AreElementsEqual(new[] { "value1", "value2" }, bag["key"]);
bag.SetValue("key", "value");
Assert.AreElementsEqual(new[] { "value" }, bag["key"]);
}