本文整理汇总了C#中System.Xml.Serialization.XmlSerializer.FromTypes方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSerializer.FromTypes方法的具体用法?C# XmlSerializer.FromTypes怎么用?C# XmlSerializer.FromTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.FromTypes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Xml.Serialization;
/* Three classes are included here. Each one will
be used to create three XmlSerializer objects. */
public class Instrument
{
public string InstrumentName;
}
public class Player
{
public string PlayerName;
}
public class Piece
{
public string PieceName;
}
public class Test
{
public static void Main()
{
Test t = new Test();
t.GetSerializers();
}
public void GetSerializers()
{
// Create an array of types.
Type[]types = new Type[3];
types[0] = typeof(Instrument);
types[1] = typeof(Player);
types[2] = typeof(Piece);
// Create an array for XmlSerializer objects.
XmlSerializer[]serializers= new XmlSerializer[3];
serializers = XmlSerializer.FromTypes(types);
// Create one Instrument and serialize it.
Instrument i = new Instrument();
i.InstrumentName = "Piano";
// Create a TextWriter to write with.
TextWriter writer = new StreamWriter("Inst.xml");
serializers[0].Serialize(writer,i);
writer.Close();
}
}