本文整理汇总了C#中System.Xml.Serialization.XmlArrayItemAttribute.Type属性的典型用法代码示例。如果您正苦于以下问题:C# XmlArrayItemAttribute.Type属性的具体用法?C# XmlArrayItemAttribute.Type怎么用?C# XmlArrayItemAttribute.Type使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Xml.Serialization.XmlArrayItemAttribute
的用法示例。
在下文中一共展示了XmlArrayItemAttribute.Type属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: typeof
//引入命名空间
using System;
using System.IO;
using System.Xml.Serialization;
public class Group
{
/* The Type property instructs the XmlSerializer to accept both
the Person and Manager types in the array. */
[XmlArrayItem(Type = typeof(Manager)),
XmlArrayItem(Type=typeof(Person))]
public Person[]Staff;
}
public class Person
{
public string Name;
}
public class Manager:Person
{
public int Rank;
}
public class Run
{
public static void Main()
{
Run test = new Run();
test.SerializeOrder("TypeEx.xml");
}
public void SerializeOrder(string filename)
{
// Creates an XmlSerializer.
XmlSerializer xSer =
new XmlSerializer(typeof(Group));
// Creates the Group object, and two array items.
Group myGroup = new Group();
Person p1 = new Person();
p1.Name = "Jacki";
Manager p2 = new Manager();
p2.Name = "Megan";
p2.Rank = 2;
Person [] myStaff = {p1,p2};
myGroup.Staff = myStaff;
// Serializes the object, and closes the StreamWriter.
TextWriter writer = new StreamWriter(filename);
xSer.Serialize(writer, myGroup);
}
}