NetDataContractSerializer.WriteEndObject Metodo

Definizione

Scrive l'elemento XML di chiusura utilizzando il writer specificato.

Overload

Nome Descrizione
WriteEndObject(XmlDictionaryWriter)

Scrive l'elemento XML di chiusura utilizzando un oggetto XmlDictionaryWriter.

WriteEndObject(XmlWriter)

Scrive l'elemento XML di chiusura utilizzando un oggetto XmlWriter.

Commenti

I WriteStartObjectmetodi , WriteObjectContente WriteEndObject vengono usati in successione per scrivere la serializzazione completa usando il modello: inizio scrittura, scrittura contenuto e fine scrittura. I tre metodi vengono chiamati anche dal WriteObject metodo .

WriteEndObject(XmlDictionaryWriter)

Scrive l'elemento XML di chiusura utilizzando un oggetto 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)

Parametri

writer
XmlDictionaryWriter

Oggetto XmlDictionaryWriter utilizzato per scrivere il documento o il flusso XML.

Eccezioni

writer è impostato su null.

Esempio

Nell'esempio seguente viene creato un oggetto da serializzare, un'istanza NetDataContractSerializerdi e un'istanza della XmlDictionaryWriter classe . Nell'esempio vengono utilizzati i WriteStartObjectmetodi , WriteObjectContente WriteEndObject per scrivere i dati dell'oggetto nel documento 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

Si applica a

WriteEndObject(XmlWriter)

Scrive l'elemento XML di chiusura utilizzando un oggetto 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)

Parametri

writer
XmlWriter

Oggetto XmlWriter utilizzato per scrivere il documento o il flusso XML.

Eccezioni

writer è impostato su null.

Si applica a