Language

DataContractSerializer.WriteEndObject メソッド

定義

指定したライターを使用して終了 XML 要素を書き込みます。

オーバーロード

名前 説明
WriteEndObject(XmlDictionaryWriter)

XmlDictionaryWriterを使用して終了 XML 要素を書き込みます。

WriteEndObject(XmlWriter)

XmlWriterを使用して終了 XML 要素を書き込みます。

WriteEndObject(XmlDictionaryWriter)

ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs

XmlDictionaryWriterを使用して終了 XML 要素を書き込みます。

public:
 override void WriteEndObject(System::Xml::XmlDictionaryWriter ^ writer);
public override void WriteEndObject(System.Xml.XmlDictionaryWriter writer);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public override void WriteEndObject(System.Xml.XmlDictionaryWriter writer);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public override void WriteEndObject(System.Xml.XmlDictionaryWriter writer);
override this.WriteEndObject : System.Xml.XmlDictionaryWriter -> unit
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
override this.WriteEndObject : System.Xml.XmlDictionaryWriter -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
override this.WriteEndObject : System.Xml.XmlDictionaryWriter -> unit
Public Overrides Sub WriteEndObject (writer As XmlDictionaryWriter)

パラメーター

writer
XmlDictionaryWriter

ストリームの書き込みに使用する XmlDictionaryWriter 。

属性

例外

シリアル化される型は、データ コントラクト規則に準拠していません。 たとえば、 DataContractAttribute 属性が型に適用されていません。

インスタンスの書き込み中に問題があります。

例

次の例では、シリアル化するオブジェクト、 DataContractSerializerのインスタンス、および XmlDictionaryWriter クラスのインスタンスを作成します。 この例では、 WriteStartObject、 WriteObjectContent、および WriteObjectContent メソッドを使用して、オブジェクト データを XML ドキュメントに書き込みます。 これらの呼び出しを行うのは、 WriteObject メソッドを 1 回呼び出すのと同じです。 たとえば、ユーザーは、 WriteStartObject メソッドを呼び出した後、XML に追加の XML 属性を挿入するために個別に呼び出しを行う場合があります。

public static void WriteObjectContentInDocument(string path)
{
    // Create the object to serialize.
    Person p = new Person("Lynn", "Tsoflias", 9876);

    // Create the writer object.
    FileStream fs = new FileStream(path, FileMode.Create);
    XmlDictionaryWriter writer =
        XmlDictionaryWriter.CreateTextWriter(fs);

    DataContractSerializer ser =
        new DataContractSerializer(typeof(Person));

    // Use the writer to start a document.
    writer.WriteStartDocument(true);

    // Use the writer to write the root element.
    writer.WriteStartElement("Company");

    // Use the writer to write an element.
    writer.WriteElementString("Name", "Microsoft");

    // Use the serializer to write the start,
    // content, and end data.
    ser.WriteStartObject(writer, p);
    ser.WriteObjectContent(writer, p);
    ser.WriteEndObject(writer);

    // Use the writer to write the end element and
    // the end of the document.
    writer.WriteEndElement();
    writer.WriteEndDocument();

    // Close and release the writer resources.
    writer.Flush();
    fs.Flush();
    fs.Close();
}
Public Shared Sub WriteObjectContentInDocument(ByVal path As String) 
    ' Create the object to serialize.
    Dim p As New Person("Lynn", "Tsoflias", 9876)
    
    ' Create the writer.
    Dim fs As New FileStream(path, FileMode.Create)
    Dim writer As XmlDictionaryWriter = XmlDictionaryWriter.CreateTextWriter(fs)
    
    Dim ser As New DataContractSerializer(GetType(Person))
    
    ' Use the writer to start a document.
    writer.WriteStartDocument(True)
    ' Use the writer to write the root element.
    writer.WriteStartElement("Company")
    ' Use the writer to write an element.
    writer.WriteElementString("Name", "Microsoft")

    ' Use the serializer to write the start,
    ' content, and end data.
    ser.WriteStartObject(writer, p)
    ser.WriteObjectContent(writer, p)
    ser.WriteEndObject(writer)
    
    ' Use the writer to write the end element and
    ' the end of the document.
    writer.WriteEndElement()
    writer.WriteEndDocument()
    
    ' Close and release the writer resources.
    writer.Flush()
    fs.Flush()
    fs.Close()

End Sub

適用対象

WriteEndObject(XmlWriter)

ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs
ソース:
DataContractSerializer.cs

XmlWriterを使用して終了 XML 要素を書き込みます。

public:
 override void WriteEndObject(System::Xml::XmlWriter ^ writer);
public override void WriteEndObject(System.Xml.XmlWriter writer);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public override void WriteEndObject(System.Xml.XmlWriter writer);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
public override void WriteEndObject(System.Xml.XmlWriter writer);
override this.WriteEndObject : System.Xml.XmlWriter -> unit
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
override this.WriteEndObject : System.Xml.XmlWriter -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")>]
override this.WriteEndObject : System.Xml.XmlWriter -> unit
Public Overrides Sub WriteEndObject (writer As XmlWriter)

パラメーター

writer
XmlWriter

ストリームの書き込みに使用する XmlWriter 。

属性

例外

シリアル化される型は、データ コントラクト規則に準拠していません。 たとえば、 DataContractAttribute 属性が型に適用されていません。

インスタンスの書き込み中に問題があります。

適用対象