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


C# XStreamingElement.WriteTo方法代码示例

本文整理汇总了C#中System.Xml.Linq.XStreamingElement.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# XStreamingElement.WriteTo方法的具体用法?C# XStreamingElement.WriteTo怎么用?C# XStreamingElement.WriteTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XStreamingElement的用法示例。


在下文中一共展示了XStreamingElement.WriteTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteXStreamingElementChildren

		public void WriteXStreamingElementChildren ()
		{
			var xml = "<?xml version='1.0' encoding='utf-8'?><root type='array'><item type='number'>0</item><item type='number'>2</item><item type='number'>5</item></root>".Replace ('\'', '"');
			
			var ms = new MemoryStream ();
			var xw = XmlWriter.Create (ms);
			int [] arr = new int [] {0, 2, 5};
			var xe = new XStreamingElement (XName.Get ("root"));
			xe.Add (new XAttribute (XName.Get ("type"), "array"));
			var at = new XAttribute (XName.Get ("type"), "number");
			foreach (var i in arr)
				xe.Add (new XStreamingElement (XName.Get ("item"), at, i));

			xe.WriteTo (xw);
			xw.Close ();
			Assert.AreEqual (xml, new StreamReader (new MemoryStream (ms.ToArray ())).ReadToEnd (), "#1");
		}
开发者ID:nobled,项目名称:mono,代码行数:17,代码来源:XStreamingElementTest.cs

示例2: WriteToWithNull

 public void WriteToWithNull()
 {
     XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134");
     Assert.Throws<ArgumentNullException>(() => streamElement.WriteTo((XmlWriter)null));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:StreamingOutput.cs

示例3: WriteToWithNull

 //[Variation(Priority = 1, Desc = "WriteTo(null)")]
 public void WriteToWithNull()
 {
     try
     {
         XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134");
         streamElement.WriteTo((XmlWriter)null);
     }
     catch (System.ArgumentNullException)
     {
         return;
     }
     throw new TestFailedException("");
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:14,代码来源:StreamingOutput.cs

示例4: AddAttributeAfterContent

 public void AddAttributeAfterContent()
 {
     XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
     XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134");
     streamElement.Add(contact.Attribute("type"));
     using (XmlWriter w = XmlWriter.Create(new MemoryStream(), null))
     {
         Assert.Throws<InvalidOperationException>(() => streamElement.WriteTo(w));
     }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:StreamingOutput.cs

示例5: AddAttributeAfterContent

 //An attribute cannot be written after content.
 //[Variation(Priority = 1, Desc = "Add(XAttribute) After Content is Added)")]
 public void AddAttributeAfterContent()
 {
     try
     {
         XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
         XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134");
         streamElement.Add(contact.Attribute("type"));
         using (XmlWriter w = XmlWriter.Create(new MemoryStream(), null))
         {
             streamElement.WriteTo(w);
         }
     }
     catch (System.InvalidOperationException)
     {
         return;
     }
     throw new TestFailedException("");
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:20,代码来源:StreamingOutput.cs


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