EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

XmlObjectSerializer Class

May 11, 2014

Provides the base class used to serialize objects as XML streams or documents. This class is abstract.

System.Object
  System.Runtime.Serialization.XmlObjectSerializer
    System.Runtime.Serialization.DataContractSerializer

Namespace:  System.Runtime.Serialization
Assembly:  System.Runtime.Serialization (in System.Runtime.Serialization.dll)

public abstract class XmlObjectSerializer

The XmlObjectSerializer type exposes the following members.

  NameDescription
Protected methodXmlObjectSerializerInitializes a new instance of the XmlObjectSerializer class.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsStartObject(XmlDictionaryReader)Gets a value that specifies whether the XmlDictionaryReader is positioned over an XML element that can be read.
Public methodIsStartObject(XmlReader)Gets a value that specifies whether the XmlReader is positioned over an XML element that can be read.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodReadObject(Stream)Reads the XML stream or document with a Stream and returns the deserialized object.
Public methodReadObject(XmlDictionaryReader)Reads the XML document or stream with an XmlDictionaryReader and returns the deserialized object.
Public methodReadObject(XmlReader)Reads the XML document or stream with an XmlReader and returns the deserialized object.
Public methodReadObject(XmlDictionaryReader, Boolean)When implemented in a derived class, reads the XML stream or document with an XmlDictionaryReader and returns the deserialized object.
Public methodReadObject(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.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodWriteEndObject(XmlDictionaryWriter)Writes the end of the object data as a closing XML element to the XML document or stream with an XmlDictionaryWriter.
Public methodWriteEndObject(XmlWriter)Writes the end of the object data as a closing XML element to the XML document or stream with an XmlWriter.
Public methodWriteObject(Stream, Object)Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified Stream.
Public methodWriteObject(XmlDictionaryWriter, Object)Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified XmlDictionaryWriter.
Public methodWriteObject(XmlWriter, Object)Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified XmlWriter.
Public methodWriteObjectContent(XmlDictionaryWriter, Object)Writes only the content of the object to the XML document or stream using the specified XmlDictionaryWriter.
Public methodWriteObjectContent(XmlWriter, Object)Writes only the content of the object to the XML document or stream with the specified XmlWriter.
Public methodWriteStartObject(XmlDictionaryWriter, Object)Writes the start of the object's data as an opening XML element using the specified XmlDictionaryWriter.
Public methodWriteStartObject(XmlWriter, Object)Writes the start of the object's data as an opening XML element using the specified XmlWriter.
Top

ExceptionCondition
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 inherits 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), and XmlObjectSerializer.WriteEndObject(XmlDictionaryWriter). Additionally, the IsStartObject and ReadObject methods must be implemented for reading and deserializing.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Afficher:
© 2014 Microsoft