XmlObjectSerializer.WriteObjectContent Method

Definition

Writes only the content of an object to an XML document or stream.

Overloads

WriteObjectContent(XmlDictionaryWriter, Object)

Writes only the content of the object to the XML document or stream using the specified XmlDictionaryWriter.

WriteObjectContent(XmlWriter, Object)

Writes only the content of the object to the XML document or stream with the specified XmlWriter.

Remarks

The WriteStartObject, WriteObjectContent, and WriteEndObject methods must be implemented. The three methods are used in succession to write the complete serialization using the pattern: write start, write content, and write end. If the implementation writes using XML elements, attributes can be inserted before writing the contents of the object. The three methods are also called by the virtual implementation of the WriteObject method.

WriteObjectContent(XmlDictionaryWriter, Object)

Source:
XmlObjectSerializer.cs
Source:
XmlObjectSerializer.cs
Source:
XmlObjectSerializer.cs

Writes only the content of the object to the XML document or stream using the specified XmlDictionaryWriter.

C#
public abstract void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph);
C#
public abstract void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object? graph);

Parameters

writer
XmlDictionaryWriter

An XmlDictionaryWriter 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.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

WriteObjectContent(XmlWriter, Object)

Source:
XmlObjectSerializer.cs
Source:
XmlObjectSerializer.cs
Source:
XmlObjectSerializer.cs

Writes only the content of the object to the XML document or stream with the specified XmlWriter.

C#
public virtual void WriteObjectContent(System.Xml.XmlWriter writer, object graph);
C#
public virtual void WriteObjectContent(System.Xml.XmlWriter writer, object? graph);

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.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0