XmlObjectSerializer Class
Provides the base class used to serialize objects as XML streams or documents. This class is abstract.
Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)
System.Runtime.Serialization::XmlObjectSerializer
System.Runtime.Serialization::DataContractSerializer
System.Runtime.Serialization.Json::DataContractJsonSerializer
System.Runtime.Serialization::NetDataContractSerializer
| Name | Description | |
|---|---|---|
![]() | XmlObjectSerializer() | Initializes a new instance of the XmlObjectSerializer class. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | IsStartObject(XmlDictionaryReader^) | Gets a value that specifies whether the XmlDictionaryReader is positioned over an XML element that can be read. |
![]() | IsStartObject(XmlReader^) | Gets a value that specifies whether the XmlReader is positioned over an XML element that can be read. |
![]() | MemberwiseClone() | |
![]() | ReadObject(Stream^) | Reads the XML stream or document with a Stream and returns the deserialized object. |
![]() | ReadObject(XmlDictionaryReader^) | Reads the XML document or stream with an XmlDictionaryReader and returns the deserialized object. |
![]() | ReadObject(XmlDictionaryReader^, Boolean) | Reads the XML stream or document with an XmlDictionaryReader and returns the deserialized object; it also enables you to specify whether the serializer can read the data before attempting to read it. |
![]() | ReadObject(XmlReader^) | Reads the XML document or stream with an XmlReader and returns the deserialized object. |
![]() | ReadObject(XmlReader^, Boolean) | Reads the XML document or stream with an XmlReader and returns the deserialized object; it also enables you to specify whether the serializer can read the data before attempting to read it. |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
![]() | WriteEndObject(XmlDictionaryWriter^) | Writes the end of the object data as a closing XML element to the XML document or stream with an XmlDictionaryWriter. |
![]() | WriteEndObject(XmlWriter^) | Writes the end of the object data as a closing XML element to the XML document or stream with an 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. |
![]() | 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. |
![]() | 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. |
![]() | WriteStartObject(XmlDictionaryWriter^, Object^) | Writes the start of the object's data as an opening XML element using the specified XmlDictionaryWriter. |
![]() | WriteStartObject(XmlWriter^, Object^) | Writes the start of the object's data as an opening XML element using the specified XmlWriter. |
| Exception | Condition |
|---|---|
| InvalidDataContractException | the type being serialized does not conform to data contract rules. For example, the DataContractAttribute attribute has not been applied to the type. |
| SerializationException | there is a problem with the instance being serialized. |
Extend the XmlObjectSerializer to create your own serializer to serialize and deserialize objects. Both the DataContractSerializer class and the NetDataContractSerializer class inherit from the XmlObjectSerializer and are used to serialize and deserialize objects that conform to data contract rules (objects created using the DataContractAttribute and the DataMemberAttribute).
Notes to Inheritors:
When you inherit from XmlObjectSerializer, you must override the following members: XmlObjectSerializer::WriteStartObject(XmlDictionaryWriter^, Object^), XmlObjectSerializer::WriteObjectContent(XmlDictionaryWriter^, Object^), XmlObjectSerializer::WriteEndObject(XmlDictionaryWriter^). Additionally, the IsStartObject and ReadObject methods must be implemented for reading and deserializing.
The following example shows a method named WriteObjectWithInstance that includes an XmlObjectSerializer as a parameter. The method serializes an object using either the DataContractSerializer or NetDataContractSerializer by calling the WriteObject method.
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

