当前位置: 首页>>代码示例>>C#>>正文


C# PropertyBag.SetValue方法代码示例

本文整理汇总了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);
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:33,代码来源:PropertyBagTests.cs

示例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"));
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:19,代码来源:DataRowTest.cs

示例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"]);
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:23,代码来源:PropertyBagTest.cs


注:本文中的PropertyBag.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。