本文整理汇总了C#中System.Xml.Serialization.XmlArrayAttribute.ElementName属性的典型用法代码示例。如果您正苦于以下问题:C# XmlArrayAttribute.ElementName属性的具体用法?C# XmlArrayAttribute.ElementName怎么用?C# XmlArrayAttribute.ElementName使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Xml.Serialization.XmlArrayAttribute
的用法示例。
在下文中一共展示了XmlArrayAttribute.ElementName属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
public class Library
{
private Book[] books;
[XmlArray(ElementName="My_Books")]
public Book[] Books
{
get{return books;}
set{books = value;}
}
}
public class Book
{
public string Title;
public string Author;
public string ISBN;
}
public class Run
{
public static void Main()
{
Run test = new Run();
test.WriteBook("ArrayExample.xml");
}
public void WriteBook(string filename)
{
XmlSerializer mySerializer = new XmlSerializer(typeof(Library));
TextWriter t = new StreamWriter(filename);
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("bk", "http://wwww.contoso.com");
Book b1 = new Book();
b1.Title = "MyBook Title";
b1.Author = "An Author";
b1.ISBN = "00000000";
Book b2 = new Book();
b2.Title = "Another Title";
b2.Author = "Another Author";
b2.ISBN = "0000000";
Library myLibrary = new Library();
Book[] myBooks = {b1,b2};
myLibrary.Books = myBooks;
mySerializer.Serialize(t,myLibrary,ns);
t.Close();
}
}