本文整理汇总了C#中System.Xml.Serialization.XmlIncludeAttribute.Type属性的典型用法代码示例。如果您正苦于以下问题:C# XmlIncludeAttribute.Type属性的具体用法?C# XmlIncludeAttribute.Type怎么用?C# XmlIncludeAttribute.Type使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。
在下文中一共展示了XmlIncludeAttribute.Type属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Xml.Serialization;
public class Group
{
public Employee[] Employees;
}
// Instruct the XmlSerializer to accept Manager types as well.
[XmlInclude(typeof(Manager))]
public class Employee
{
public string Name;
}
public class Manager:Employee
{
public int Level;
}
public class Run
{
public static void Main()
{
Run test = new Run();
test.SerializeObject("IncludeExample.xml");
test.DeserializeObject("IncludeExample.xml");
}
public void SerializeObject(string filename)
{
XmlSerializer s = new XmlSerializer(typeof(Group));
TextWriter writer = new StreamWriter(filename);
Group group = new Group();
Manager manager = new Manager();
Employee emp1 = new Employee();
Employee emp2 = new Employee();
manager.Name = "Zeus";
manager.Level = 2;
emp1.Name = "Ares";
emp2.Name = "Artemis";
Employee [] emps = new Employee[3]{manager, emp1, emp2};
group.Employees = emps;
s.Serialize(writer, group);
writer.Close();
}
public void DeserializeObject(string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open);
XmlSerializer x = new XmlSerializer(typeof(Group));
Group g = (Group) x.Deserialize(fs);
Console.Write("Members:");
foreach(Employee e in g.Employees)
{
Console.WriteLine("\t" + e.Name);
}
}
}
开发者ID:.NET开发者,项目名称:System.Xml.Serialization,代码行数:68,代码来源:XmlIncludeAttribute.Type
注:本文中的System.Xml.Serialization.XmlIncludeAttribute.Type属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论