Edit

Share via


DataContractSerializer Class

Definition

Serializes and deserializes an instance of a type into an XML stream or document using a supplied data contract. This class cannot be inherited.

public ref class DataContractSerializer sealed : System::Runtime::Serialization::XmlObjectSerializer
public sealed class DataContractSerializer : System.Runtime.Serialization.XmlObjectSerializer
type DataContractSerializer = class
    inherit XmlObjectSerializer
Public NotInheritable Class DataContractSerializer
Inherits XmlObjectSerializer
Inheritance
DataContractSerializer

Remarks

For more information about this API, see Supplemental API remarks for DataContractSerializer.

Constructors

DataContractSerializer(Type)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type.

DataContractSerializer(Type, DataContractSerializerSettings)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type and settings.

DataContractSerializer(Type, IEnumerable<Type>)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type, and a collection of known types that may be present in the object graph.

DataContractSerializer(Type, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type. This method also specifies a list of known types that may be present in the object graph, the maximum number of graph items to serialize, parameters to ignore unexpected data, whether to use non-standard XML constructs to preserve object reference data in the graph, and a surrogate for custom serialization.

DataContractSerializer(Type, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate, DataContractResolver)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type. This method also specifies a list of known types that may be present in the object graph, the maximum number of graph items to serialize, parameters to ignore unexpected data, whether to use non-standard XML constructs to preserve object reference data in the graph, a surrogate for custom serialization, and an alternative for mapping xsi:type declarations at run time.

DataContractSerializer(Type, String, String)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type using the supplied XML root element and namespace.

DataContractSerializer(Type, String, String, IEnumerable<Type>)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type. This method also specifies the root XML element and namespace in two string parameters as well as a list of known types that may be present in the object graph.

DataContractSerializer(Type, String, String, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type. This method also specifies a list of known types that may be present in the object graph, the maximum number of graph items to serialize, parameters to ignore unexpected data, whether to use non-standard XML constructs to preserve object reference data in the graph, a surrogate for custom serialization, and the XML element and namespace that contain the content.

DataContractSerializer(Type, String, String, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate, DataContractResolver)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type. This method also specifies a list of known types that may be present in the object graph, the maximum number of graph items to serialize, parameters to ignore unexpected data, whether to use non-standard XML constructs to preserve object reference data in the graph, a surrogate for custom serialization, the XML element and namespace that contains the content, and an alternative for mapping xsi:type declarations at run time.

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type using the XML root element and namespace specified through the parameters of type XmlDictionaryString.

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type. This method also specifies the root XML element and namespace in two XmlDictionaryString parameters as well as a list of known types that may be present in the object graph.

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type. This method also specifies a list of known types that may be present in the object graph, the maximum number of graph items to serialize, parameters to ignore unexpected data, whether to use non-standard XML constructs to preserve object reference data in the graph, a surrogate for custom serialization, and parameters of XmlDictionaryString that specify the XML element and namespace that contain the content.

DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>, Int32, Boolean, Boolean, IDataContractSurrogate, DataContractResolver)

Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type. This method also specifies a list of known types that may be present in the object graph, the maximum number of graph items to serialize, parameters to ignore unexpected data, whether to use non-standard XML constructs to preserve object reference data in the graph, a surrogate for custom serialization, parameters of XmlDictionaryString that specify the XML element and namespace that contains the content, and an alternative for mapping xsi:type declarations at run time.

Properties

DataContractResolver

Gets the component used to dynamically map xsi:type declarations to known contract types.

DataContractSurrogate

Gets a surrogate type that can extend the serialization or deserialization process.

IgnoreExtensionDataObject

Gets a value that specifies whether to ignore data supplied by an extension of the class when the class is being serialized or deserialized.

KnownTypes

Gets a collection of types that may be present in the object graph serialized using this instance of the DataContractSerializer.

MaxItemsInObjectGraph

Gets the maximum number of items in an object graph to serialize or deserialize.

PreserveObjectReferences

Gets a value that specifies whether to use non-standard XML constructs to preserve object reference data.

SerializeReadOnlyTypes

Gets a value that specifies whether read-only types are serialized.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IsStartObject(XmlDictionaryReader)

Determines whether the XmlDictionaryReader is positioned on an object that can be deserialized.

IsStartObject(XmlReader)

Determines whether the XmlReader is positioned on an object that can be deserialized.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ReadObject(Stream)

Reads the XML stream or document with a Stream and returns the deserialized object.

(Inherited from XmlObjectSerializer)
ReadObject(XmlDictionaryReader)

Reads the XML document or stream with an XmlDictionaryReader and returns the deserialized object.

(Inherited from XmlObjectSerializer)
ReadObject(XmlDictionaryReader, Boolean)

Reads the XML stream with an XmlDictionaryReader and returns the deserialized object, and also specifies whether a check is made to verify the object name before reading its value.

ReadObject(XmlDictionaryReader, Boolean, DataContractResolver)

Reads an XML document or document stream and returns the deserialized object. The method includes a parameter to specify whether the object name is verified is validated, and a resolver for mapping xsi:type declarations at runtime.

ReadObject(XmlReader)

Reads the XML stream with an XmlReader and returns the deserialized object.

ReadObject(XmlReader, Boolean)

Reads the XML stream with an XmlReader and returns the deserialized object, and also specifies whether a check is made to verify the object name before reading its value.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
WriteEndObject(XmlDictionaryWriter)

Writes the closing XML element using an XmlDictionaryWriter.

WriteEndObject(XmlWriter)

Writes the closing XML element using 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.

(Inherited from XmlObjectSerializer)
WriteObject(XmlDictionaryWriter, Object)

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

(Inherited from XmlObjectSerializer)
WriteObject(XmlDictionaryWriter, Object, DataContractResolver)

Writes all the object data (starting XML element, content, and enclosing element) to an XML document or stream using the specified XmlDictionaryWriter. The method includes a resolver for mapping xsi:type declarations at runtime.

WriteObject(XmlWriter, Object)

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

WriteObjectContent(XmlDictionaryWriter, Object)

Writes the XML content using an XmlDictionaryWriter.

WriteObjectContent(XmlWriter, Object)

Writes the XML content using an XmlWriter.

WriteStartObject(XmlDictionaryWriter, Object)

Writes the opening XML element using an XmlDictionaryWriter.

WriteStartObject(XmlWriter, Object)

Writes the opening XML element using an XmlWriter.

Extension Methods

GetSerializationSurrogateProvider(DataContractSerializer)

Returns the surrogate serialization provider for this serializer.

SetSerializationSurrogateProvider(DataContractSerializer, ISerializationSurrogateProvider)

Specifies a surrogate serialization provider for this DataContractSerializer.

Applies to

Thread Safety

Instances of this class are thread safe except when the instance is used with an implementation of the IDataContractSurrogate or DataContractResolver.

See also