NetDataContractSerializer.WriteEndObject Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
A záró XML-elemet a megadott íróval írja.
Túlterhelések
| Name | Description |
|---|---|
| WriteEndObject(XmlDictionaryWriter) |
A záró XML-elemet egy XmlDictionaryWriter. |
| WriteEndObject(XmlWriter) |
A záró XML-elemet egy XmlWriter. |
Megjegyzések
A WriteStartObject, WriteObjectContentés WriteEndObject metódusok egymás után a teljes szerializálás megírására szolgálnak a következő mintával: írás kezdete, tartalom írása és írás vége. A három metódust a WriteObject metódus is meghívja.
WriteEndObject(XmlDictionaryWriter)
A záró XML-elemet egy 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)
Paraméterek
- writer
- XmlDictionaryWriter
Az XmlDictionaryWriter XML-dokumentum vagy -adatfolyam írásához használt.
Kivételek
a writer értéke .null
Példák
Az alábbi példa létrehoz egy szerializálandó objektumot, az NetDataContractSerializerosztály egy példányát és egy példányát XmlDictionaryWriter . A példa a WriteStartObject, WriteObjectContentés WriteEndObject metódusok használatával írja be az objektumadatokat az XML-dokumentumba.
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
A következőre érvényes:
WriteEndObject(XmlWriter)
A záró XML-elemet egy 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)
Paraméterek
Kivételek
a writer értéke .null