XmlObjectSerializer.WriteObject Method

Definition

Writes all the object data (starting XML element, content, and closing element) to an XML document or stream.

Overloads

WriteObject(Stream, Object)

Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified Stream.

WriteObject(XmlDictionaryWriter, Object)

Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified XmlDictionaryWriter.

WriteObject(XmlWriter, Object)

Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified XmlWriter.

WriteObject(Stream, Object)

Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified Stream.

public:
 virtual void WriteObject(System::IO::Stream ^ stream, System::Object ^ graph);
public virtual void WriteObject (System.IO.Stream stream, object graph);
public virtual void WriteObject (System.IO.Stream stream, object? graph);
abstract member WriteObject : System.IO.Stream * obj -> unit
override this.WriteObject : System.IO.Stream * obj -> unit
Public Overridable Sub WriteObject (stream As Stream, graph As Object)

Parameters

stream
Stream

A Stream used to write the XML document or stream.

graph
Object

The object that contains the data to write to the stream.

Exceptions

the type being serialized does not conform to data contract rules. For example, the DataContractAttribute attribute has not been applied to the type.

there is a problem with the instance being serialized.

the maximum number of objects to serialize has been exceeded. Check the MaxItemsInObjectGraph property.

Applies to

WriteObject(XmlDictionaryWriter, Object)

Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified XmlDictionaryWriter.

public:
 virtual void WriteObject(System::Xml::XmlDictionaryWriter ^ writer, System::Object ^ graph);
public virtual void WriteObject (System.Xml.XmlDictionaryWriter writer, object graph);
public virtual void WriteObject (System.Xml.XmlDictionaryWriter writer, object? graph);
abstract member WriteObject : System.Xml.XmlDictionaryWriter * obj -> unit
override this.WriteObject : System.Xml.XmlDictionaryWriter * obj -> unit
Public Overridable Sub WriteObject (writer As XmlDictionaryWriter, graph As Object)

Parameters

writer
XmlDictionaryWriter

An XmlDictionaryWriter used to write the content to the XML document or stream.

graph
Object

The object that contains the content to write.

Exceptions

the type being serialized does not conform to data contract rules. For example, the DataContractAttribute attribute has not been applied to the type.

there is a problem with the instance being serialized.

the maximum number of objects to serialize has been exceeded. Check the MaxItemsInObjectGraph property.

Remarks

This is a virtual method and has a default implementation that calls the WriteStartObject, WriteObjectContent, and WriteEndObject methods. Because of this, this method is intended to be the most commonly used method on a serializer.

Applies to

WriteObject(XmlWriter, Object)

Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified XmlWriter.

public:
 virtual void WriteObject(System::Xml::XmlWriter ^ writer, System::Object ^ graph);
public virtual void WriteObject (System.Xml.XmlWriter writer, object graph);
public virtual void WriteObject (System.Xml.XmlWriter writer, object? graph);
abstract member WriteObject : System.Xml.XmlWriter * obj -> unit
override this.WriteObject : System.Xml.XmlWriter * obj -> unit
Public Overridable Sub WriteObject (writer As XmlWriter, graph As Object)

Parameters

writer
XmlWriter

An XmlWriter used to write the XML document or stream.

graph
Object

The object that contains the content to write.

Exceptions

the type being serialized does not conform to data contract rules. For example, the DataContractAttribute attribute has not been applied to the type.

there is a problem with the instance being serialized.

the maximum number of objects to serialize has been exceeded. Check the MaxItemsInObjectGraph property.

Remarks

This is a virtual method, and has a default implementation that delegates writing to the XmlObjectSerializer.WriteObject(XmlDictionaryWriter, Object) overload.

Applies to