XmlSerializer.Serialize メソッド

定義

オブジェクトを XML ドキュメントにシリアル化します。

オーバーロード

Serialize(XmlWriter, Object)

指定した Object をシリアル化し、生成された XML ドキュメントを、指定した XmlWriter を使用してファイルに書き込みます。

Serialize(XmlWriter, Object, XmlSerializerNamespaces, String, String)

指定した Object をシリアル化し、指定した XmlWriter、XML 名前空間、およびエンコーディングを使用して、XML ドキュメントをファイルに書き込みます。

Serialize(XmlWriter, Object, XmlSerializerNamespaces, String)

指定したオブジェクトをシリアル化し、指定した XmlWriter を使用して、指定した名前空間とエンコード スタイルを参照し、生成された XML ドキュメントをファイルに書き込みます。

Serialize(XmlWriter, Object, XmlSerializerNamespaces)

指定した Object をシリアル化し、指定した XmlWriter を使用して XML ドキュメントをファイルに書き込み、指定した名前空間を参照します。

Serialize(TextWriter, Object, XmlSerializerNamespaces)

指定した Object をシリアル化し、指定した TextWriter を使用して XML ドキュメントをファイルに書き込み、指定した名前空間を参照します。

Serialize(Object, XmlSerializationWriter)

指定した Object をシリアル化し、生成された XML ドキュメントを、指定した XmlSerializationWriter を使用してファイルに書き込みます。

Serialize(TextWriter, Object)

指定した Object をシリアル化し、生成された XML ドキュメントを、指定した TextWriter を使用してファイルに書き込みます。

Serialize(Stream, Object)

指定した Object をシリアル化し、生成された XML ドキュメントを、指定した Stream を使用してファイルに書き込みます。

Serialize(Stream, Object, XmlSerializerNamespaces)

指定した Object をシリアル化し、指定した Stream を使用して、指定した名前空間を参照し、生成された XML ドキュメントをファイルに書き込みます。

Serialize(XmlWriter, Object)

指定した Object をシリアル化し、生成された XML ドキュメントを、指定した XmlWriter を使用してファイルに書き込みます。

public:
 void Serialize(System::Xml::XmlWriter ^ xmlWriter, System::Object ^ o);
public void Serialize (System.Xml.XmlWriter xmlWriter, object o);
public void Serialize (System.Xml.XmlWriter xmlWriter, object? o);
member this.Serialize : System.Xml.XmlWriter * obj -> unit
Public Sub Serialize (xmlWriter As XmlWriter, o As Object)

パラメーター

xmlWriter
XmlWriter

XML ドキュメントを書き込むために使用する XmlWriter

o
Object

シリアル化する Object

例外

シリアル化中にエラーが発生しました。 元の例外には、InnerException プロパティを使用してアクセスできます。

次の例では、 を使用して オブジェクトを XmlWriterシリアル化します。

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Xml;
using namespace System::Xml::Serialization;

// This is the class that will be serialized.
public ref class OrderedItem
{
public:
   String^ ItemName;
   String^ Description;
   Decimal UnitPrice;
   int Quantity;
   Decimal LineTotal;

   // A custom method used to calculate price per item.
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
};

void SerializeObject( String^ filename )
{
   Console::WriteLine( "Writing With XmlTextWriter" );
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );
   OrderedItem^ i = gcnew OrderedItem;
   i->ItemName = "Widget";
   i->Description = "Regular Widget";
   i->Quantity = 10;
   i->UnitPrice = (Decimal)2.30;
   i->Calculate();

   // Create an XmlTextWriter using a FileStream.
   Stream^ fs = gcnew FileStream( filename,FileMode::Create );
   XmlWriter^ writer = gcnew XmlTextWriter( fs,Encoding::Unicode );

   // Serialize using the XmlTextWriter.
   serializer->Serialize( writer, i );
   writer->Close();
}

int main()
{
   // Write a purchase order.
   SerializeObject( "simple.xml" );
}
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class OrderedItem4
{
    public string ItemName;
    public string Description;
    public decimal UnitPrice;
    public int Quantity;
    public decimal LineTotal;
    // A custom method used to calculate price per item.
    public void Calculate()
    {
        LineTotal = UnitPrice * Quantity;
    }
}

public class Test4
{
    public static void Main()
    {
        Test4 t = new();
        // Write a purchase order.
        t.SerializeObject("simple.xml");
    }

    private void SerializeObject(string filename)
    {
        Console.WriteLine("Writing With XmlTextWriter");

        XmlSerializer serializer = new(typeof(OrderedItem4));
        OrderedItem4 i = new()
        {
            ItemName = "Widget",
            Description = "Regular Widget",
            Quantity = 10,
            UnitPrice = (decimal)2.30
        };
        i.Calculate();
        // Create an XmlTextWriter using a FileStream.
        Stream fs = new FileStream(filename, FileMode.Create);
        XmlTextWriter writer = new(fs, Encoding.Unicode);
        // Serialize using the XmlTextWriter.
        serializer.Serialize(writer, i);
        writer.Close();
    }
}
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization


' This is the class that will be serialized.
Public Class OrderedItem
    Public ItemName As String
    Public Description As String
    Public UnitPrice As Decimal
    Public Quantity As Integer
    Public LineTotal As Decimal
    
    ' A custom method used to calculate price per item.
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class


Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        ' Write a purchase order.
        t.SerializeObject("simple.xml")
    End Sub
        
    Private Sub SerializeObject(ByVal filename As String)
        Console.WriteLine("Writing With XmlTextWriter")
        
        Dim serializer As New XmlSerializer(GetType(OrderedItem))
        Dim i As New OrderedItem()
        With i
            .ItemName = "Widget"
            .Description = "Regular Widget"
            .Quantity = 10
            .UnitPrice = CDec(2.3)
            .Calculate()
        End With
        ' Create an XmlTextWriter using a FileStream.
        Dim fs As New FileStream(filename, FileMode.Create)
        Dim writer As New XmlTextWriter(fs, Encoding.Unicode)
        ' Serialize using the XmlTextWriter.
        serializer.Serialize(writer, i)
        writer.Close()
    End Sub
End Class
<?xml version="1.0"?>
 <OrderedItem xmlns:inventory="http://www.cpandl.com" xmlns:money="http://www.cohowinery.com">
   <inventory:ItemName>Widget</inventory:ItemName>
   <inventory:Description>Regular Widget</inventory:Description>
   <money:UnitPrice>2.3</money:UnitPrice>
   <inventory:Quantity>10</inventory:Quantity>
   <money:LineTotal>23</money:LineTotal>
 </OrderedItem>

注釈

メソッドは Serialize 、オブジェクトのパブリック フィールドと読み取り/書き込みプロパティを XML に変換します。 メソッド、インデクサー、プライベート フィールド、読み取り専用プロパティは変換されません。

パラメーターで xmlWriter 、抽象 XmlWriter クラスから派生するオブジェクトを指定します。 は XmlTextWriter から派生します XmlWriter

注意

では XmlSerializer 、 の配列と の配列 ArrayListList<T>シリアル化できません。

こちらもご覧ください

適用対象

Serialize(XmlWriter, Object, XmlSerializerNamespaces, String, String)

指定した Object をシリアル化し、指定した XmlWriter、XML 名前空間、およびエンコーディングを使用して、XML ドキュメントをファイルに書き込みます。

public:
 void Serialize(System::Xml::XmlWriter ^ xmlWriter, System::Object ^ o, System::Xml::Serialization::XmlSerializerNamespaces ^ namespaces, System::String ^ encodingStyle, System::String ^ id);
public void Serialize (System.Xml.XmlWriter xmlWriter, object? o, System.Xml.Serialization.XmlSerializerNamespaces? namespaces, string? encodingStyle, string? id);
public void Serialize (System.Xml.XmlWriter xmlWriter, object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces, string encodingStyle, string id);
member this.Serialize : System.Xml.XmlWriter * obj * System.Xml.Serialization.XmlSerializerNamespaces * string * string -> unit
Public Sub Serialize (xmlWriter As XmlWriter, o As Object, namespaces As XmlSerializerNamespaces, encodingStyle As String, id As String)

パラメーター

xmlWriter
XmlWriter

XML ドキュメントを書き込むために使用する XmlWriter

o
Object

シリアル化するオブジェクト。

namespaces
XmlSerializerNamespaces

使用する名前空間とプレフィックスを格納している XmlSerializerNamespaces のインスタンス。

encodingStyle
String

ドキュメントで使用するエンコーディング。

id
String

SOAP エンコード済みメッセージの場合に、id 属性の生成に使用される基本文字列。

注釈

id パラメーターは、SOAP ID の作成に使用される基本文字列を提供します。 既定では、これらは "id1"、"id2" などです。 ただし、パラメーターが "myBase" に設定されている場合、生成される値は "myBaseid1"、"myBaseid2" などになります。 この機能は、SOAP メッセージ全体で一意の ID 値を作成するために使用されます。

適用対象

Serialize(XmlWriter, Object, XmlSerializerNamespaces, String)

指定したオブジェクトをシリアル化し、指定した XmlWriter を使用して、指定した名前空間とエンコード スタイルを参照し、生成された XML ドキュメントをファイルに書き込みます。

public:
 void Serialize(System::Xml::XmlWriter ^ xmlWriter, System::Object ^ o, System::Xml::Serialization::XmlSerializerNamespaces ^ namespaces, System::String ^ encodingStyle);
public void Serialize (System.Xml.XmlWriter xmlWriter, object? o, System.Xml.Serialization.XmlSerializerNamespaces? namespaces, string? encodingStyle);
public void Serialize (System.Xml.XmlWriter xmlWriter, object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces, string encodingStyle);
member this.Serialize : System.Xml.XmlWriter * obj * System.Xml.Serialization.XmlSerializerNamespaces * string -> unit
Public Sub Serialize (xmlWriter As XmlWriter, o As Object, namespaces As XmlSerializerNamespaces, encodingStyle As String)

パラメーター

xmlWriter
XmlWriter

XML ドキュメントを書き込むために使用する XmlWriter

o
Object

シリアル化するオブジェクト。

namespaces
XmlSerializerNamespaces

オブジェクトが参照する XmlSerializerNamespaces

encodingStyle
String

シリアル化された XML のエンコード スタイル。

例外

シリアル化中にエラーが発生しました。 元の例外には、InnerException プロパティを使用してアクセスできます。

注釈

メソッドが Serialize 呼び出されると、オブジェクトのパブリック フィールドと読み取り/書き込みプロパティが XML に変換されます。 メソッド、インデクサー、プライベート フィールド、読み取り専用プロパティはシリアル化されません。

パラメーターを xmlWriter 使用して、XML ドキュメントを記述するように設計された抽象 XmlWriter クラスから派生するオブジェクトを指定します。 は XmlTextWriter から派生します XmlWriter

パラメーターを "http://schemas.xmlsoap.org/soap/encoding/" に設定しますencodingStyle。SOAP バージョン 1.1 エンコードの場合。それ以外の場合は、 を "http://www.w3.org/2001/12/soap-encoding"に設定します。SOAP バージョン 1.2 エンコードの場合。

注意

では XmlSerializer 、 の配列と の配列 ArrayListList<T>シリアル化できません。

こちらもご覧ください

適用対象

Serialize(XmlWriter, Object, XmlSerializerNamespaces)

指定した Object をシリアル化し、指定した XmlWriter を使用して XML ドキュメントをファイルに書き込み、指定した名前空間を参照します。

public:
 void Serialize(System::Xml::XmlWriter ^ xmlWriter, System::Object ^ o, System::Xml::Serialization::XmlSerializerNamespaces ^ namespaces);
public void Serialize (System.Xml.XmlWriter xmlWriter, object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces);
public void Serialize (System.Xml.XmlWriter xmlWriter, object? o, System.Xml.Serialization.XmlSerializerNamespaces? namespaces);
member this.Serialize : System.Xml.XmlWriter * obj * System.Xml.Serialization.XmlSerializerNamespaces -> unit
Public Sub Serialize (xmlWriter As XmlWriter, o As Object, namespaces As XmlSerializerNamespaces)

パラメーター

xmlWriter
XmlWriter

XML ドキュメントを書き込むために使用する XmlWriter

o
Object

シリアル化する Object

namespaces
XmlSerializerNamespaces

オブジェクトが参照する XmlSerializerNamespaces

例外

シリアル化中にエラーが発生しました。 元の例外には、InnerException プロパティを使用してアクセスできます。

次の例では、 を使用して オブジェクトを XmlWriterシリアル化します。 この例では、 を XmlSerializerNamespaces 作成し、 オブジェクトに 2 つの名前空間を追加します。 クラスの複数のインスタンスが XmlElementAttribute クラス メンバーに適用され、各要素の名前空間が指定されます。

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Xml;
using namespace System::Xml::Serialization;

// This is the class that will be serialized.
public ref class OrderedItem
{
public:

   [XmlElement(Namespace="http://www.cpandl.com")]
   String^ ItemName;

   [XmlElement(Namespace="http://www.cpandl.com")]
   String^ Description;

   [XmlElement(Namespace="http://www.cohowinery.com")]
   Decimal UnitPrice;

   [XmlElement(Namespace="http://www.cpandl.com")]
   int Quantity;

   [XmlElement(Namespace="http://www.cohowinery.com")]
   Decimal LineTotal;

   // A custom method used to calculate price per item.
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
};

void SerializeObject( String^ filename )
{
   Console::WriteLine( "Writing With XmlTextWriter" );
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );
   OrderedItem^ i = gcnew OrderedItem;
   i->ItemName = "Widget";
   i->Description = "Regular Widget";
   i->Quantity = 10;
   i->UnitPrice = (Decimal)2.30;
   i->Calculate();

   // Create an XmlSerializerNamespaces object.
   XmlSerializerNamespaces^ ns = gcnew XmlSerializerNamespaces;

   // Add two namespaces with prefixes.
   ns->Add( "inventory", "http://www.cpandl.com" );
   ns->Add( "money", "http://www.cohowinery.com" );

   // Create an XmlTextWriter using a FileStream.
   Stream^ fs = gcnew FileStream( filename,FileMode::Create );
   XmlWriter^ writer = gcnew XmlTextWriter( fs,gcnew UTF8Encoding );

   // Serialize using the XmlTextWriter.
   serializer->Serialize( writer, i, ns );
   writer->Close();
}

int main()
{
   // Write a purchase order.
   SerializeObject( "simple.xml" );
}
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class OrderedItem5
{
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public string ItemName;
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public string Description;
    [XmlElement(Namespace = "http://www.cohowinery.com")]
    public decimal UnitPrice;
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public int Quantity;
    [XmlElement(Namespace = "http://www.cohowinery.com")]
    public decimal LineTotal;
    // A custom method used to calculate price per item.
    public void Calculate()
    {
        LineTotal = UnitPrice * Quantity;
    }
}

public class Test5
{
    public static void Main()
    {
        Test5 t = new();
        // Write a purchase order.
        t.SerializeObject("simple.xml");
    }

    private void SerializeObject(string filename)
    {
        Console.WriteLine("Writing With XmlTextWriter");

        XmlSerializer serializer = new(typeof(OrderedItem5));
        OrderedItem5 i = new()
        {
            ItemName = "Widget",
            Description = "Regular Widget",
            Quantity = 10,
            UnitPrice = (decimal)2.30
        };
        i.Calculate();

        // Create an XmlSerializerNamespaces object.
        XmlSerializerNamespaces ns = new();

        // Add two namespaces with prefixes.
        ns.Add("inventory", "http://www.cpandl.com");
        ns.Add("money", "http://www.cohowinery.com");

        // Create an XmlTextWriter using a FileStream.
        Stream fs = new FileStream(filename, FileMode.Create);
        XmlTextWriter writer = new(fs, new UTF8Encoding());

        // Serialize using the XmlTextWriter.
        serializer.Serialize(writer, i, ns);
        writer.Close();
    }
}
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization


' This is the class that will be serialized.
Public Class OrderedItem
    <XmlElement(Namespace := "http://www.cpandl.com")> _
    Public ItemName As String
    
    <XmlElement(Namespace := "http://www.cpandl.com")> _
    Public Description As String
    
    <XmlElement(Namespace := "http://www.cohowinery.com")> _
    Public UnitPrice As Decimal
    
    <XmlElement(Namespace := "http://www.cpandl.com")> _
    Public Quantity As Integer
    
    <XmlElement(Namespace := "http://www.cohowinery.com")> _
    Public LineTotal As Decimal
    
    'A custom method used to calculate price per item.
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class


Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        ' Write a purchase order.
        t.SerializeObject("simple.xml")
    End Sub    
    
    Private Sub SerializeObject(ByVal filename As String)
        Console.WriteLine("Writing With XmlTextWriter")
        
        Dim serializer As New XmlSerializer(GetType(OrderedItem))
        Dim i As New OrderedItem()
        With i
            .ItemName = "Widget"
            .Description = "Regular Widget"
            .Quantity = 10
            .UnitPrice = CDec(2.3)
            .Calculate()
        End With
        
        ' Create an XmlSerializerNamespaces object.
        Dim ns As New XmlSerializerNamespaces()
        ' Add two namespaces with prefixes.
        ns.Add("inventory", "http://www.cpandl.com")
        ns.Add("money", "http://www.cohowinery.com")
        ' Create an XmlTextWriter using a FileStream.
        Dim fs As New FileStream(filename, FileMode.Create)
        Dim writer As New XmlTextWriter(fs, New UTF8Encoding())
        ' Serialize using the XmlTextWriter.
        serializer.Serialize(writer, i, ns)
        writer.Close()
    End Sub
End Class
<?xml version="1.0"?>
 <OrderedItem xmlns:inventory="http://www.cpandl.com" xmlns:money="http://www.cohowinery.com">
   <inventory:ItemName>Widget</inventory:ItemName>
   <inventory:Description>Regular Widget</inventory:Description>
   <money:UnitPrice>2.3</money:UnitPrice>
   <inventory:Quantity>10</inventory:Quantity>
   <money:LineTotal>23</money:LineTotal>
 </OrderedItem>

注釈

メソッドが Serialize 呼び出されると、オブジェクトのパブリック フィールドと読み取り/書き込みプロパティが XML に変換されます。 メソッド、インデクサー、プライベート フィールド、読み取り専用プロパティはシリアル化されません。

パラメーターを xmlWriter 使用して、XML ドキュメントを記述するように設計された抽象 XmlWriter クラスから派生するオブジェクトを指定します。 は XmlTextWriter から派生します XmlWriter

注意

では XmlSerializer 、 の配列と の配列 ArrayListList<T>シリアル化できません。

こちらもご覧ください

適用対象

Serialize(TextWriter, Object, XmlSerializerNamespaces)

指定した Object をシリアル化し、指定した TextWriter を使用して XML ドキュメントをファイルに書き込み、指定した名前空間を参照します。

public:
 void Serialize(System::IO::TextWriter ^ textWriter, System::Object ^ o, System::Xml::Serialization::XmlSerializerNamespaces ^ namespaces);
public void Serialize (System.IO.TextWriter textWriter, object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces);
public void Serialize (System.IO.TextWriter textWriter, object? o, System.Xml.Serialization.XmlSerializerNamespaces? namespaces);
member this.Serialize : System.IO.TextWriter * obj * System.Xml.Serialization.XmlSerializerNamespaces -> unit
Public Sub Serialize (textWriter As TextWriter, o As Object, namespaces As XmlSerializerNamespaces)

パラメーター

textWriter
TextWriter

XML ドキュメントを書き込むために使用する TextWriter

o
Object

シリアル化する Object

namespaces
XmlSerializerNamespaces

生成された XML ドキュメントで使用する名前空間を格納している XmlSerializerNamespaces

例外

シリアル化中にエラーが発生しました。 元の例外には、InnerException プロパティを使用してアクセスできます。

次の例では、 を使用して オブジェクトを TextWriterシリアル化します。 この例では、 オブジェクトも XmlSerializerNamespaces 作成し、 オブジェクトに 2 つの名前空間を追加します。 シリアル化されたオブジェクトを定義するクラスには、各要素の名前空間を指定する属性も含 XmlElementAttribute まれます。

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;

// This is the class that will be serialized.
public ref class OrderedItem
{
public:

   [XmlElement(Namespace="http://www.cpandl.com")]
   String^ ItemName;

   [XmlElement(Namespace="http://www.cpandl.com")]
   String^ Description;

   [XmlElement(Namespace="http://www.cohowinery.com")]
   Decimal UnitPrice;

   [XmlElement(Namespace="http://www.cpandl.com")]
   int Quantity;

   [XmlElement(Namespace="http://www.cohowinery.com")]
   Decimal LineTotal;

   // A custom method used to calculate price per item.
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
};

void SerializeObject( String^ filename )
{
   Console::WriteLine( "Writing With TextWriter" );

   // Create an XmlSerializer instance using the type.
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );
   OrderedItem^ i = gcnew OrderedItem;
   i->ItemName = "Widget";
   i->Description = "Regular Widget";
   i->Quantity = 10;
   i->UnitPrice = (Decimal)2.30;
   i->Calculate();

   // Create an XmlSerializerNamespaces object.
   XmlSerializerNamespaces^ ns = gcnew XmlSerializerNamespaces;

   // Add two namespaces with prefixes.
   ns->Add( "inventory", "http://www.cpandl.com" );
   ns->Add( "money", "http://www.cohowinery.com" );

   // Create a StreamWriter to write with.
   TextWriter^ writer = gcnew StreamWriter( filename );

   /* Serialize using the object using the TextWriter 
      and namespaces. */
   serializer->Serialize( writer, i, ns );
   writer->Close();
}

int main()
{
   // Write a purchase order.
   SerializeObject( "simple.xml" );
}
using System;
using System.IO;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class OrderedItem1
{
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public string ItemName;
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public string Description;
    [XmlElement(Namespace = "http://www.cohowinery.com")]
    public decimal UnitPrice;
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public int Quantity;
    [XmlElement(Namespace = "http://www.cohowinery.com")]
    public decimal LineTotal;
    // A custom method used to calculate price per item.
    public void Calculate()
    {
        LineTotal = UnitPrice * Quantity;
    }
}

public class Test1
{
    public static void Main(string[] args)
    {
        Test1 t = new();
        // Write a purchase order.
        t.SerializeObject("simple.xml");
    }

    private void SerializeObject(string filename)
    {
        Console.WriteLine("Writing With TextWriter");
        // Create an XmlSerializer instance using the type.
        XmlSerializer serializer = new(typeof(OrderedItem1));
        OrderedItem1 i = new()
        {
            ItemName = "Widget",
            Description = "Regular Widget",
            Quantity = 10,
            UnitPrice = (decimal)2.30
        };
        i.Calculate();

        // Create an XmlSerializerNamespaces object.
        XmlSerializerNamespaces ns = new();
        // Add two namespaces with prefixes.
        ns.Add("inventory", "http://www.cpandl.com");
        ns.Add("money", "http://www.cohowinery.com");
        // Create a StreamWriter to write with.
        StreamWriter writer = new(filename);
        /* Serialize using the object using the TextWriter
        and namespaces. */
        serializer.Serialize(writer, i, ns);
        writer.Close();
    }
}
Imports System.IO
Imports System.Xml.Serialization


' This is the class that will be serialized.
Public Class OrderedItem
    <XmlElement(Namespace := "http://www.cpandl.com")> _
    Public ItemName As String
    
    <XmlElement(Namespace := "http://www.cpandl.com")> _
    Public Description As String
    
    <XmlElement(Namespace := "http://www.cohowinery.com")> _
    Public UnitPrice As Decimal
    
    <XmlElement(Namespace := "http://www.cpandl.com")> _
    Public Quantity As Integer
    
    <XmlElement(Namespace := "http://www.cohowinery.com")> _
    Public LineTotal As Decimal
    
    'A custom method used to calculate price per item.
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class


Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        ' Write a purchase order.
        t.SerializeObject("simple.xml")
    End Sub
    
    Private Sub SerializeObject(ByVal filename As String)
        Console.WriteLine("Writing With TextWriter")
        ' Create an XmlSerializer instance using the type.
        Dim serializer As New XmlSerializer(GetType(OrderedItem))
        Dim i As New OrderedItem()
        i.ItemName = "Widget"
        i.Description = "Regular Widget"
        i.Quantity = 10
        i.UnitPrice = CDec(2.3)
        i.Calculate()
        
        ' Create an XmlSerializerNamespaces object.
        Dim ns As New XmlSerializerNamespaces()
        ' Add two namespaces with prefixes.
        ns.Add("inventory", "http://www.cpandl.com")
        ns.Add("money", "http://www.cohowinery.com")
        ' Create a StreamWriter to write with.
        Dim writer As New StreamWriter(filename)
        ' Serialize using the object using the TextWriter
        ' and namespaces. 
        serializer.Serialize(writer, i, ns)
        writer.Close()
    End Sub
End Class
<?xml version="1.0"?>
 <OrderedItem xmlns:inventory="http://www.cpandl.com" xmlns:money="http://www.cohowinery.com">
   <inventory:ItemName>Widget</inventory:ItemName>
   <inventory:Description>Regular Widget</inventory:Description>
   <money:UnitPrice>2.3</money:UnitPrice>
   <inventory:Quantity>10</inventory:Quantity>
   <money:LineTotal>23</money:LineTotal>
 </OrderedItem>

注釈

メソッドが Serialize 呼び出されると、パブリック フィールドとオブジェクトの読み取り/書き込みプロパティが XML に変換されます。 メソッド、インデクサー、プライベート フィールド、読み取り専用プロパティはシリアル化されません。

textWriter抽象TextWriterクラスから派生するオブジェクトを指定するには、 パラメーターを使用します。 クラスから TextWriter 派生するクラスは次のとおりです。

注意

では XmlSerializer 、 の配列と の配列 ArrayListList<T>シリアル化できません。

こちらもご覧ください

適用対象

Serialize(Object, XmlSerializationWriter)

指定した Object をシリアル化し、生成された XML ドキュメントを、指定した XmlSerializationWriter を使用してファイルに書き込みます。

protected:
 virtual void Serialize(System::Object ^ o, System::Xml::Serialization::XmlSerializationWriter ^ writer);
protected virtual void Serialize (object? o, System.Xml.Serialization.XmlSerializationWriter writer);
protected virtual void Serialize (object o, System.Xml.Serialization.XmlSerializationWriter writer);
abstract member Serialize : obj * System.Xml.Serialization.XmlSerializationWriter -> unit
override this.Serialize : obj * System.Xml.Serialization.XmlSerializationWriter -> unit
Protected Overridable Sub Serialize (o As Object, writer As XmlSerializationWriter)

パラメーター

o
Object

シリアル化する Object

writer
XmlSerializationWriter

XML ドキュメントを書き込むために使用する XmlSerializationWriter

例外

メソッドが派生クラスでオーバーライドされない場合は、そのメソッドへのアクセスが行われます。

適用対象

Serialize(TextWriter, Object)

指定した Object をシリアル化し、生成された XML ドキュメントを、指定した TextWriter を使用してファイルに書き込みます。

public:
 void Serialize(System::IO::TextWriter ^ textWriter, System::Object ^ o);
public void Serialize (System.IO.TextWriter textWriter, object o);
public void Serialize (System.IO.TextWriter textWriter, object? o);
member this.Serialize : System.IO.TextWriter * obj -> unit
Public Sub Serialize (textWriter As TextWriter, o As Object)

パラメーター

textWriter
TextWriter

XML ドキュメントを書き込むために使用する TextWriter

o
Object

シリアル化する Object

次の例では、 を使用して オブジェクトを TextWriterシリアル化します。

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Xml::Serialization;

// This is the class that will be serialized.
public ref class OrderedItem
{
public:
   String^ ItemName;
   String^ Description;
   Decimal UnitPrice;
   int Quantity;
   Decimal LineTotal;

   // A custom method used to calculate price per item.
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
};

void SerializeObject( String^ filename )
{
   Console::WriteLine( "Writing With TextWriter" );
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );
   OrderedItem^ i = gcnew OrderedItem;
   i->ItemName = "Widget";
   i->Description = "Regular Widget";
   i->Quantity = 10;
   i->UnitPrice = (Decimal)2.30;
   i->Calculate();

   /* Create a StreamWriter to write with. First create a FileStream
      object, and create the StreamWriter specifying an Encoding to use. */
   FileStream^ fs = gcnew FileStream( filename,FileMode::Create );
   TextWriter^ writer = gcnew StreamWriter( fs,gcnew UTF8Encoding );

   // Serialize using the XmlTextWriter.
   serializer->Serialize( writer, i );
   writer->Close();
}

int main()
{
   // Write a purchase order.
   SerializeObject( "simple.xml" );
}
using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class OrderedItem
{
    public string ItemName;
    public string Description;
    public decimal UnitPrice;
    public int Quantity;
    public decimal LineTotal;
    // A custom method used to calculate price per item.
    public void Calculate()
    {
        LineTotal = UnitPrice * Quantity;
    }
}

public class Test
{
    public static void Main(string[] args)
    {
        Test t = new();
        // Write a purchase order.
        t.SerializeObject("simple.xml");
    }

    private void SerializeObject(string filename)
    {
        Console.WriteLine("Writing With TextWriter");

        XmlSerializer serializer = new(typeof(OrderedItem));
        OrderedItem i = new()
        {
            ItemName = "Widget",
            Description = "Regular Widget",
            Quantity = 10,
            UnitPrice = (decimal)2.30
        };
        i.Calculate();

        /* Create a StreamWriter to write with. First create a FileStream
           object, and create the StreamWriter specifying an Encoding to use. */
        FileStream fs = new(filename, FileMode.Create);
        StreamWriter writer = new(fs, new UTF8Encoding());
        // Serialize using the XmlTextWriter.
        serializer.Serialize(writer, i);
        writer.Close();
    }
}
Imports System.IO
Imports System.Text
Imports System.Xml.Serialization


' This is the class that will be serialized.
Public Class OrderedItem
    Public ItemName As String
    Public Description As String
    Public UnitPrice As Decimal
    Public Quantity As Integer
    Public LineTotal As Decimal
    
    'A custom method used to calculate price per item.
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class


Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        ' Write a purchase order.
        t.SerializeObject("simple.xml")
    End Sub
    
    Private Sub SerializeObject(ByVal filename As String)
        Console.WriteLine("Writing With TextWriter")
        
        Dim serializer As New XmlSerializer(GetType(OrderedItem))
        Dim i As New OrderedItem()

        With i
            .ItemName = "Widget"
            .Description = "Regular Widget"
            .Quantity = 10
            .UnitPrice = CDec(2.3)
            .Calculate()
        End With
        
        ' Create a StreamWriter to write with. First create a FileStream
        ' object, and create the StreamWriter specifying an Encoding to use. 
        Dim fs As New FileStream(filename, FileMode.Create)
        Dim writer As New StreamWriter(fs, New UTF8Encoding())
        ' Serialize using the XmlTextWriter.
        serializer.Serialize(writer, i)
        writer.Close()
    End Sub
End Class
<?xml version="1.0"?>
 <OrderedItem xmlns:inventory="http://www.cpandl.com" xmlns:money="http://www.cohowinery.com">
   <inventory:ItemName>Widget</inventory:ItemName>
   <inventory:Description>Regular Widget</inventory:Description>
   <money:UnitPrice>2.3</money:UnitPrice>
   <inventory:Quantity>10</inventory:Quantity>
   <money:LineTotal>23</money:LineTotal>
 </OrderedItem>

注釈

メソッドは Serialize 、オブジェクトのパブリック フィールドと読み取り/書き込みプロパティを XML に変換します。 メソッド、インデクサー、プライベート フィールド、読み取り専用プロパティは変換されません。

パラメーターで textWriter 、抽象 TextWriter クラスから派生するオブジェクトを指定します。 から TextWriter 派生するクラスは次のとおりです。

注意

では XmlSerializer 、 の配列と の配列 ArrayListList<T>シリアル化できません。

こちらもご覧ください

適用対象

Serialize(Stream, Object)

指定した Object をシリアル化し、生成された XML ドキュメントを、指定した Stream を使用してファイルに書き込みます。

public:
 void Serialize(System::IO::Stream ^ stream, System::Object ^ o);
public void Serialize (System.IO.Stream stream, object o);
public void Serialize (System.IO.Stream stream, object? o);
member this.Serialize : System.IO.Stream * obj -> unit
Public Sub Serialize (stream As Stream, o As Object)

パラメーター

stream
Stream

XML ドキュメントを書き込むために使用する Stream

o
Object

シリアル化する Object

例外

シリアル化中にエラーが発生しました。 元の例外には、InnerException プロパティを使用してアクセスできます。

次の例では、 オブジェクトを使用して オブジェクトを Stream シリアル化します。

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;

// This is the class that will be serialized.
public ref class OrderedItem
{
public:
   String^ ItemName;
   String^ Description;
   Decimal UnitPrice;
   int Quantity;
   Decimal LineTotal;

   // A custom method used to calculate price per item.
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
};

void SerializeObject( String^ filename )
{
   Console::WriteLine( "Writing With Stream" );
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );
   OrderedItem^ i = gcnew OrderedItem;
   i->ItemName = "Widget";
   i->Description = "Regular Widget";
   i->Quantity = 10;
   i->UnitPrice = (Decimal)2.30;
   i->Calculate();

   // Create a FileStream to write with.
   Stream^ writer = gcnew FileStream( filename,FileMode::Create );

   // Serialize the object, and close the TextWriter
   serializer->Serialize( writer, i );
   writer->Close();
}

int main()
{
   // Write a purchase order.
   SerializeObject( "simple.xml" );
}
using System;
using System.IO;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class OrderedItem2
{
    public string ItemName;
    public string Description;
    public decimal UnitPrice;
    public int Quantity;
    public decimal LineTotal;

    // A custom method used to calculate price per item.
    public void Calculate()
    {
        LineTotal = UnitPrice * Quantity;
    }
}

public class Test2
{
    public static void Main(string[] args)
    {
        Test2 t = new();
        // Write a purchase order.
        t.SerializeObject("simple.xml");
    }

    private void SerializeObject(string filename)
    {
        Console.WriteLine("Writing With Stream");

        XmlSerializer serializer = new(typeof(OrderedItem2));
        OrderedItem2 i = new()
        {
            ItemName = "Widget",
            Description = "Regular Widget",
            Quantity = 10,
            UnitPrice = (decimal)2.30
        };
        i.Calculate();

        // Create a FileStream to write with.
        FileStream writer = new(filename, FileMode.Create);
        // Serialize the object, and close the TextWriter
        serializer.Serialize(writer, i);
        writer.Close();
    }
}
Imports System.IO
Imports System.Xml.Serialization


' This is the class that will be serialized.
Public Class OrderedItem
    Public ItemName As String
    Public Description As String
    Public UnitPrice As Decimal
    Public Quantity As Integer
    Public LineTotal As Decimal
    
    
    ' A custom method used to calculate price per item.
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class


Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        ' Write a purchase order.
        t.SerializeObject("simple.xml")
    End Sub
    
    Private Sub SerializeObject(ByVal filename As String)
        Console.WriteLine("Writing With Stream")
        
        Dim serializer As New XmlSerializer(GetType(OrderedItem))
        Dim i As New OrderedItem()

        With i
            .ItemName = "Widget"
            .Description = "Regular Widget"
            .Quantity = 10
            .UnitPrice = CDec(2.3)
            .Calculate()
        End With
        
        ' Create a FileStream to write with.
        Dim writer As New FileStream(filename, FileMode.Create)
        ' Serialize the object, and close the TextWriter
        serializer.Serialize(writer, i)
        writer.Close()
    End Sub
End Class
<?xml version="1.0"?>
 <OrderedItem xmlns:inventory="http://www.cpandl.com" xmlns:money="http://www.cohowinery.com">
   <inventory:ItemName>Widget</inventory:ItemName>
   <inventory:Description>Regular Widget</inventory:Description>
   <money:UnitPrice>2.3</money:UnitPrice>
   <inventory:Quantity>10</inventory:Quantity>
   <money:LineTotal>23</money:LineTotal>
 </OrderedItem>

注釈

メソッドは Serialize 、オブジェクトのパブリック フィールドと読み取り/書き込みプロパティを XML に変換します。 メソッド、インデクサー、プライベート フィールド、読み取り専用プロパティは変換されません。

パラメーターで stream 、抽象 Stream クラスから派生するオブジェクトを指定します。 から Stream 派生するクラスは次のとおりです。

注意

では XmlSerializer 、 の配列と の配列 ArrayListList<T>シリアル化できません。

こちらもご覧ください

適用対象

Serialize(Stream, Object, XmlSerializerNamespaces)

指定した Object をシリアル化し、指定した Stream を使用して、指定した名前空間を参照し、生成された XML ドキュメントをファイルに書き込みます。

public:
 void Serialize(System::IO::Stream ^ stream, System::Object ^ o, System::Xml::Serialization::XmlSerializerNamespaces ^ namespaces);
public void Serialize (System.IO.Stream stream, object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces);
public void Serialize (System.IO.Stream stream, object? o, System.Xml.Serialization.XmlSerializerNamespaces? namespaces);
member this.Serialize : System.IO.Stream * obj * System.Xml.Serialization.XmlSerializerNamespaces -> unit
Public Sub Serialize (stream As Stream, o As Object, namespaces As XmlSerializerNamespaces)

パラメーター

stream
Stream

XML ドキュメントを書き込むために使用する Stream

o
Object

シリアル化する Object

namespaces
XmlSerializerNamespaces

オブジェクトが参照する XmlSerializerNamespaces

例外

シリアル化中にエラーが発生しました。 元の例外には、InnerException プロパティを使用してアクセスできます。

次の例では、 オブジェクトを 使用して オブジェクトを Stream シリアル化します。 この例では、 を XmlSerializerNamespaces 作成し、 オブジェクトに 2 つの名前空間を追加します。 シリアル化されたオブジェクトを定義するクラスには、各要素の名前空間を指定する属性も含 XmlElementAttribute まれます。

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;

// This is the class that will be serialized.
public ref class OrderedItem
{
public:

   [XmlElement(Namespace="http://www.cpandl.com")]
   String^ ItemName;

   [XmlElement(Namespace="http://www.cpandl.com")]
   String^ Description;

   [XmlElement(Namespace="http://www.cohowinery.com")]
   Decimal UnitPrice;

   [XmlElement(Namespace="http://www.cpandl.com")]
   int Quantity;

   [XmlElement(Namespace="http://www.cohowinery.com")]
   Decimal LineTotal;

   // A custom method used to calculate price per item.
   void Calculate()
   {
      LineTotal = UnitPrice * Quantity;
   }
};

void SerializeObject( String^ filename )
{
   Console::WriteLine( "Writing With Stream" );
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );
   OrderedItem^ i = gcnew OrderedItem;
   i->ItemName = "Widget";
   i->Description = "Regular Widget";
   i->Quantity = 10;
   i->UnitPrice = (Decimal)2.30;
   i->Calculate();

   // Create an XmlSerializerNamespaces object.
   XmlSerializerNamespaces^ ns = gcnew XmlSerializerNamespaces;

   // Add two prefix-namespace pairs.
   ns->Add( "inventory", "http://www.cpandl.com" );
   ns->Add( "money", "http://www.cohowinery.com" );

   // Create a FileStream to write with.
   Stream^ writer = gcnew FileStream( filename,FileMode::Create );

   // Serialize the object, and close the TextWriter
   serializer->Serialize( writer, i, ns );
   writer->Close();
}

void DeserializeObject( String^ filename )
{
   Console::WriteLine( "Reading with Stream" );

   // Create an instance of the XmlSerializer.
   XmlSerializer^ serializer = gcnew XmlSerializer( OrderedItem::typeid );

   // Writing the file requires a Stream.
   Stream^ reader = gcnew FileStream( filename,FileMode::Open );

   // Declare an object variable of the type to be deserialized.
   OrderedItem^ i;

   /* Use the Deserialize method to restore the object's state 
      using data from the XML document. */
   i = dynamic_cast<OrderedItem^>(serializer->Deserialize( reader ));

   // Write out the properties of the object.
   Console::Write( "{0}\t{1}\t{2}\t{3}\t{4}", i->ItemName, i->Description, i->UnitPrice, i->Quantity, i->LineTotal );
}

int main()
{
   // Write a purchase order.
   SerializeObject( "simple.xml" );
   DeserializeObject( "simple.xml" );
}
using System;
using System.IO;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class OrderedItem3
{
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public string ItemName;
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public string Description;
    [XmlElement(Namespace = "http://www.cohowinery.com")]
    public decimal UnitPrice;
    [XmlElement(Namespace = "http://www.cpandl.com")]
    public int Quantity;
    [XmlElement(Namespace = "http://www.cohowinery.com")]
    public decimal LineTotal;

    // A custom method used to calculate price per item.
    public void Calculate()
    {
        LineTotal = UnitPrice * Quantity;
    }
}

public class Test3
{
    public static void Main()
    {
        Test3 t = new();
        // Write a purchase order.
        t.SerializeObject("simple.xml");
        t.DeserializeObject("simple.xml");
    }

    private void SerializeObject(string filename)
    {
        Console.WriteLine("Writing With Stream");

        XmlSerializer serializer =
            new(typeof(OrderedItem3));

        OrderedItem3 i = new()
        {
            ItemName = "Widget",
            Description = "Regular Widget",
            Quantity = 10,
            UnitPrice = (decimal)2.30
        };
        i.Calculate();

        // Create an XmlSerializerNamespaces object.
        XmlSerializerNamespaces ns = new();

        // Add two prefix-namespace pairs.
        ns.Add("inventory", "http://www.cpandl.com");
        ns.Add("money", "http://www.cohowinery.com");

        // Create a FileStream to write with.
        FileStream writer = new(filename, FileMode.Create);

        // Serialize the object, and close the TextWriter
        serializer.Serialize(writer, i, ns);
        writer.Close();
    }

    private void DeserializeObject(string filename)
    {
        Console.WriteLine("Reading with Stream");
        // Create an instance of the XmlSerializer.
        XmlSerializer serializer = new(typeof(OrderedItem3));

        // Writing the file requires a Stream.
        Stream reader = new FileStream(filename, FileMode.Open);

        // Declare an object variable of the type to be deserialized.
        OrderedItem3 i;

        /* Use the Deserialize method to restore the object's state
           using data from the XML document. */
        i = (OrderedItem3)serializer.Deserialize(reader);

        // Write out the properties of the object.
        Console.Write(
            i.ItemName + "\t" +
            i.Description + "\t" +
            i.UnitPrice + "\t" +
            i.Quantity + "\t" +
            i.LineTotal);
    }
}
Imports System.IO
Imports System.Xml.Serialization

' This is the class that will be serialized.
Public Class OrderedItem
    <XmlElement(Namespace := "http://www.cpandl.com")> _
    Public ItemName As String
    
    <XmlElement(Namespace := "http://www.cpandl.com")> _
    Public Description As String
    
    <XmlElement(Namespace := "http://www.cohowinery.com")> _
    Public UnitPrice As Decimal
    
    <XmlElement(Namespace := "http://www.cpandl.com")> _
    Public Quantity As Integer
    
    <XmlElement(Namespace := "http://www.cohowinery.com")> _
    Public LineTotal As Decimal
    
    ' A custom method used to calculate price per item.
    Public Sub Calculate()
        LineTotal = UnitPrice * Quantity
    End Sub
End Class

Public Class Test
        
    Public Shared Sub Main()
        Dim t As New Test()
        ' Write a purchase order.
        t.SerializeObject("simple.xml")
        t.DeserializeObject("simple.xml")
    End Sub    
    
    Private Sub SerializeObject(ByVal filename As String)
        Console.WriteLine("Writing With Stream")
        
        Dim serializer As New XmlSerializer(GetType(OrderedItem))
        
        Dim i As New OrderedItem()
        With i
            .ItemName = "Widget"
            .Description = "Regular Widget"
            .Quantity = 10
            .UnitPrice = CDec(2.3)
            .Calculate()
        End With
        
        ' Create an XmlSerializerNamespaces object.
        Dim ns As New XmlSerializerNamespaces()
        
        ' Add two prefix-namespace pairs.
        ns.Add("inventory", "http://www.cpandl.com")
        ns.Add("money", "http://www.cohowinery.com")
        
        ' Create a FileStream to write with.
        Dim writer As New FileStream(filename, FileMode.Create)
        
        ' Serialize the object, and close the TextWriter
        serializer.Serialize(writer, i, ns)
        writer.Close()
    End Sub
        
    Private Sub DeserializeObject(ByVal filename As String)
        Console.WriteLine("Reading with Stream")
        ' Create an instance of the XmlSerializer.
        Dim serializer As New XmlSerializer(GetType(OrderedItem))
        
        ' Writing the file requires a Stream.
        Dim reader As New FileStream(filename, FileMode.Open)
        
        ' Declare an object variable of the type to be deserialized.
        Dim i As OrderedItem
        
        ' Use the Deserialize method to restore the object's state
        ' using data from the XML document. 
        i = CType(serializer.Deserialize(reader), OrderedItem)
        
        ' Write out the properties of the object.
        Console.Write(i.ItemName & ControlChars.Tab & _
                      i.Description & ControlChars.Tab & _
                      i.UnitPrice & ControlChars.Tab & _
                      i.Quantity & ControlChars.Tab & _
                      i.LineTotal)
    End Sub
End Class

注釈

メソッドが Serialize 呼び出されると、オブジェクトのパブリック フィールドと読み取り/書き込みプロパティが XML に変換されます。 メソッド、インデクサー、プライベート フィールド、読み取り専用プロパティはシリアル化されません。

パラメーターを stream 使用して、ストリームに書き込むよう設計された抽象 Stream クラスから派生するオブジェクトを指定します。 クラスから派生するクラスは Stream 次のとおりです。

注意

では XmlSerializer 、 の配列と の配列 ArrayListList<T>シリアル化できません。

こちらもご覧ください

適用対象