Sdílet prostřednictvím


NetDataContractSerializer.WriteEndObject Metoda

Definice

Zapíše uzavírací element XML pomocí zadaného zapisovače.

Přetížení

WriteEndObject(XmlDictionaryWriter)

Zapíše uzavírací element XML pomocí XmlDictionaryWriter.

WriteEndObject(XmlWriter)

Zapíše uzavírací element XML pomocí XmlWriter.

Poznámky

Metody WriteStartObject, WriteObjectContenta WriteEndObject se používají v posloupnosti k zápisu úplné serializace pomocí vzoru: write start, write content, and write end. Tři metody jsou volána také metodou WriteObject .

WriteEndObject(XmlDictionaryWriter)

Zapíše uzavírací element XML pomocí XmlDictionaryWriter.

public:
 override void WriteEndObject(System::Xml::XmlDictionaryWriter ^ writer);
public override void WriteEndObject (System.Xml.XmlDictionaryWriter writer);
override this.WriteEndObject : System.Xml.XmlDictionaryWriter -> unit
Public Overrides Sub WriteEndObject (writer As XmlDictionaryWriter)

Parametry

writer
XmlDictionaryWriter

Slouží XmlDictionaryWriter k zápisu dokumentu XML nebo datového proudu.

Výjimky

hodnota je writer nastavená na null.

Příklady

Následující příklad vytvoří objekt serializovat, instanci NetDataContractSerializer, a instanci XmlDictionaryWriter třídy. Příklad používá WriteStartObjectmetody , WriteObjectContenta WriteEndObject k zápisu dat objektu do dokumentu XML.

public sealed class ShowWriteStartObject
{

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

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

        NetDataContractSerializer ser =
            new NetDataContractSerializer();

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

        // Use the serializer to write the start of the
        // object data. Use it again to write the object
        // data.
        ser.WriteStartObject(writer, p);
        ser.WriteObjectContent(writer, p);

        // Use the serializer to write the end of the
        // object data. Then use the writer to write the end
        // of the document.
        ser.WriteEndObject(writer);
        writer.WriteEndDocument();

        Console.WriteLine("Done");

        // Close and release the writer resources.
        writer.Flush();
        fs.Flush();
        fs.Close();
    }
NotInheritable Public Class ShowWriteStartObject
     
    Public Shared Sub WriteObjectData(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 System.Runtime.Serialization.NetDataContractSerializer()        

        ' Use the writer to start a document.
        writer.WriteStartDocument(True)
        
        ' Use the serializer to write the start of the 
        ' object data. Use it again to write the object
        ' data. 
        ser.WriteStartObject(writer, p)
        writer.WriteStartAttribute("MyAttribute")
        writer.WriteString("My Text")
        writer.WriteEndAttribute()

        ser.WriteObjectContent(writer, p)
                
        ' Use the serializer to write the end of the 
        ' object data. Then use the writer to write the end
        ' of the document.
        ser.WriteEndObject(writer)
        writer.WriteEndDocument()
        
        Console.WriteLine("Done")
        
        ' Close and release the writer resources.
        writer.Flush()
        fs.Flush()
        fs.Close()
    
    End Sub

Platí pro

WriteEndObject(XmlWriter)

Zapíše uzavírací element XML pomocí XmlWriter.

public:
 override void WriteEndObject(System::Xml::XmlWriter ^ writer);
public override void WriteEndObject (System.Xml.XmlWriter writer);
override this.WriteEndObject : System.Xml.XmlWriter -> unit
Public Overrides Sub WriteEndObject (writer As XmlWriter)

Parametry

writer
XmlWriter

Slouží XmlWriter k zápisu dokumentu XML nebo datového proudu.

Výjimky

hodnota je writer nastavená na null.

Platí pro