當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。