本文整理汇总了C#中PropertyBag.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyBag.GetValue方法的具体用法?C# PropertyBag.GetValue怎么用?C# PropertyBag.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyBag
的用法示例。
在下文中一共展示了PropertyBag.GetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializationRoundtrip
public void SerializationRoundtrip ()
{
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);
SerializableObject.CreationCount = 0;
var 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: ProducesMetadata
public void ProducesMetadata()
{
string document = "value,[Metadata]\n123,abc\n456,def";
Func<TextReader> documentReaderProvider = delegate { return new StringReader(document); };
CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false);
dataSet.HasHeader = true;
dataSet.DataLocationName = "<inline>";
Assert.AreEqual("<inline>", dataSet.DataLocationName);
DataBinding binding = new DataBinding(0, null);
List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(new DataBinding[] { binding }, true));
Assert.AreEqual("123", items[0].GetValue(binding));
PropertyBag map = DataItemUtils.GetMetadata(items[0]);
Assert.AreEqual("<inline>(2)", map.GetValue(MetadataKeys.DataLocation));
Assert.AreEqual("abc", map.GetValue("Metadata"));
Assert.AreEqual("456", items[1].GetValue(binding));
map = new PropertyBag();
items[1].PopulateMetadata(map);
Assert.AreEqual("<inline>(3)", map.GetValue(MetadataKeys.DataLocation));
Assert.AreEqual("def", map.GetValue("Metadata"));
}
示例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"]);
}