Class DataContractSerializer<TDataContract>
Serializes and deserializes an instance of a type into an XML stream or document using a supplied data contract. This class cannot be inherited.
Inheritance
Namespace: Copper.Common
Assembly: Copper.Common.dll
Syntax
public sealed class DataContractSerializer<TDataContract>
where TDataContract : class
Type Parameters
Name | Description |
---|---|
TDataContract | The type of the data contract. |
Constructors
View SourceDataContractSerializer()
Initializes a new instance of the System.
Declaration
public DataContractSerializer()
DataContractSerializer(IEnumerable<Type>)
Initializes a new instance of the System.
Declaration
public DataContractSerializer(IEnumerable<Type> knownTypes)
Parameters
Type | Name | Description |
---|---|---|
System. |
knownTypes | An System.Collections.Generic.IEnumerable<T> of System. |
DataContractSerializer(DataContractSerializerSettings)
Initializes a new instance of the System.
Declaration
public DataContractSerializer(DataContractSerializerSettings settings)
Parameters
Type | Name | Description |
---|---|---|
System. |
settings | The serializer settings. |
DataContractSerializer(String, String)
Initializes a new instance of the System.
Declaration
public DataContractSerializer(string rootName, string rootNamespace)
Parameters
Type | Name | Description |
---|---|---|
System. |
rootName | The name of the XML element that encloses the content to serialize or deserialize. |
System. |
rootNamespace | The namespace of the XML element that encloses the content to serialize or deserialize. |
DataContractSerializer(String, String, IEnumerable<Type>)
Initializes a new instance of the System.
Declaration
public DataContractSerializer(string rootName, string rootNamespace, IEnumerable<Type> knownTypes)
Parameters
Type | Name | Description |
---|---|---|
System. |
rootName | The root element name of the content. |
System. |
rootNamespace | The namespace of the root element. |
System. |
knownTypes | An System.Collections.Generic.IEnumerable<T> of System. |
DataContractSerializer(XmlDictionaryString, XmlDictionaryString)
Initializes a new instance of the System.
Declaration
public DataContractSerializer(XmlDictionaryString rootName, XmlDictionaryString rootNamespace)
Parameters
Type | Name | Description |
---|---|---|
System. |
rootName | An System. |
System. |
rootNamespace | An System. |
DataContractSerializer(XmlDictionaryString, XmlDictionaryString, IEnumerable<Type>)
Initializes a new instance of the System.
Declaration
public DataContractSerializer(XmlDictionaryString rootName, XmlDictionaryString rootNamespace, IEnumerable<Type> knownTypes)
Parameters
Type | Name | Description |
---|---|---|
System. |
rootName | An System. |
System. |
rootNamespace | An System. |
System. |
knownTypes | A System.Collections.Generic.IEnumerable<T> of System. |
Properties
View SourceDataContractResolver
Gets the component used to dynamically map langword_csharp_xsi:type declarations to known contract types.
Declaration
public DataContractResolver DataContractResolver { get; }
Property Value
Type | Description |
---|---|
System. |
An implementation of the System. |
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.
Declaration
public bool IgnoreExtensionDataObject { get; }
Property Value
Type | Description |
---|---|
System. |
true to omit the extension data; otherwise, false. |
KnownTypes
Gets a collection of types that may be present in the TDataContract graph serialized using this instance of the System.
Declaration
public ReadOnlyCollection<Type> KnownTypes { get; }
Property Value
Type | Description |
---|---|
System. |
A System.Collections.ObjectModel.ReadOnlyCollection<T> that contains the expected types passed in as known types to the System. |
MaxItemsInObjectGraph
Gets the maximum number of items in an TDataContract graph to serialize or deserialize.
Declaration
public int MaxItemsInObjectGraph { get; }
Property Value
Type | Description |
---|---|
System. |
The maximum number of items to serialize or deserialize. The default is System. |
Exceptions
Type | Condition |
---|---|
System. |
The number of items exceeds the maximum value. |
PreserveObjectReferences
Gets a value that specifies whether to use non-standard XML constructs to preserve object reference data.
Declaration
public bool PreserveObjectReferences { get; }
Property Value
Type | Description |
---|---|
System. |
true to keep the references; otherwise, false. |
SerializeReadOnlyTypes
Gets a value that specifies whether read-only types are serialized.
Declaration
public bool SerializeReadOnlyTypes { get; }
Property Value
Type | Description |
---|---|
System. |
true if read-only types are serialized; false if all types are serialized. |
Methods
View SourceIsStartObject(XmlDictionaryReader)
Determines whether the System.
Declaration
public bool IsStartObject(XmlDictionaryReader reader)
Parameters
Type | Name | Description |
---|---|---|
System. |
reader | An System. |
Returns
Type | Description |
---|---|
System. |
true if the reader is at the start element of the stream to read; otherwise, false. |
IsStartObject(XmlReader)
Determines whether the System.
Declaration
public bool IsStartObject(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
System. |
reader | The System. |
Returns
Type | Description |
---|---|
System. |
true if the reader is at the start element of the stream to read; otherwise, false. |
ReadObject(Stream)
Reads the XML stream or document with a System.
Declaration
public TDataContract ReadObject(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System. |
stream | A System. |
Returns
Type | Description |
---|---|
TData |
The deserialized object. |
ReadObject(String, Encoding)
Reads the XML string with a System.
Declaration
public TDataContract ReadObject(string value, Encoding encoding = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
value | A XMLSystem. |
System. |
encoding | The System. |
Returns
Type | Description |
---|---|
TData |
The deserialized object. |
ReadObject(XmlDictionaryReader, Boolean)
Reads the XML stream with an System.
Declaration
public TDataContract ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
Parameters
Type | Name | Description |
---|---|---|
System. |
reader | The System. |
System. |
verifyObjectName | true to check whether the name of the object corresponds to the root name value supplied in the constructor; otherwise, false. |
Returns
Type | Description |
---|---|
TData |
The deserialized object. |
Exceptions
Type | Condition |
---|---|
System. |
The |
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 langword_csharp_xsi:type declarations at runtime.
Declaration
public TDataContract ReadObject(XmlDictionaryReader reader, bool verifyObjectName, DataContractResolver dataContractResolver)
Parameters
Type | Name | Description |
---|---|---|
System. |
reader | The XML reader used to read the content. |
System. |
verifyObjectName | true to verify the object name; otherwise, false. |
System. |
dataContractResolver | An implementation of the System. |
Returns
Type | Description |
---|---|
TData |
The deserialized object. |
ReadObject(XmlReader)
Reads the XML stream with an System.
Declaration
public TDataContract ReadObject(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
System. |
reader | The System. |
Returns
Type | Description |
---|---|
TData |
The deserialized object. |
ReadObject(XmlReader, Boolean)
Reads the XML stream with an System.
Declaration
public TDataContract ReadObject(XmlReader reader, bool verifyObjectName)
Parameters
Type | Name | Description |
---|---|---|
System. |
reader | The System. |
System. |
verifyObjectName | true to check whether the name of the object corresponds to the root name value supplied in the constructor; otherwise, false. |
Returns
Type | Description |
---|---|
TData |
The deserialized object. |
Exceptions
Type | Condition |
---|---|
System. |
The |
WriteEndObject(XmlDictionaryWriter)
Writes the closing XML element using an System.
Declaration
public void WriteEndObject(XmlDictionaryWriter writer)
Parameters
Type | Name | Description |
---|---|---|
System. |
writer | The System. |
Exceptions
Type | Condition |
---|---|
System. |
The type being serialized does not conform to data contract rules. For example, the System. |
System. |
There is a problem with the instance being written. |
WriteEndObject(XmlWriter)
Writes the closing XML element using an System.
Declaration
public void WriteEndObject(XmlWriter writer)
Parameters
Type | Name | Description |
---|---|---|
System. |
writer | The System. |
Exceptions
Type | Condition |
---|---|
System. |
The type being serialized does not conform to data contract rules. For example, the System. |
System. |
There is a problem with the instance being written. |
WriteObject(TDataContract)
Returns the complete content (start, content, and end) of the object as a XML System.
Declaration
public string WriteObject(TDataContract graph)
Parameters
Type | Name | Description |
---|---|---|
TData |
graph | The object that contains the data to return as a string. |
Returns
Type | Description |
---|---|
System. |
The XML string representation of the object. |
Exceptions
Type | Condition |
---|---|
System. |
the type being serialized does not conform to data contract rules. For example, the System. |
System. |
there is a problem with the instance being serialized. |
System. |
the maximum number of objects to serialize has been exceeded. Check the System. |
WriteObject(Stream, TDataContract)
Writes the complete content (start, content, and end) of the object to the XML document or stream with the specified System.
Declaration
public void WriteObject(Stream stream, TDataContract graph)
Parameters
Type | Name | Description |
---|---|---|
System. |
stream | A System. |
TData |
graph | The object that contains the data to write to the stream. |
Exceptions
Type | Condition |
---|---|
System. |
the type being serialized does not conform to data contract rules. For example, the System. |
System. |
there is a problem with the instance being serialized. |
System. |
the maximum number of objects to serialize has been exceeded. Check the System. |
WriteObject(XmlDictionaryWriter, TDataContract, 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 langword_csharp_xsi:type declarations at runtime.
Declaration
public void WriteObject(XmlDictionaryWriter writer, TDataContract graph, DataContractResolver dataContractResolver)
Parameters
Type | Name | Description |
---|---|---|
System. |
writer | An XmlDictionaryWriter used to write the content to the XML document or stream. |
TData |
graph | The object that contains the content to write. |
System. |
dataContractResolver | An implementation of the System. |
WriteObject(XmlWriter, TDataContract)
Writes all the object data (starting XML element, content, and closing element) to an XML document or stream with an System.
Declaration
public void WriteObject(XmlWriter writer, TDataContract graph)
Parameters
Type | Name | Description |
---|---|---|
System. |
writer | The System. |
TData |
graph | The object that contains the data to write to the stream. |
Exceptions
Type | Condition |
---|---|
System. |
The type being serialized does not conform to data contract rules. For example, the System. |
System. |
There is a problem with the instance being written. |
WriteObjectContent(XmlDictionaryWriter, TDataContract)
Writes the XML content using an System.
Declaration
public void WriteObjectContent(XmlDictionaryWriter writer, TDataContract graph)
Parameters
Type | Name | Description |
---|---|---|
System. |
writer | The System. |
TData |
graph | The object to write to the stream. |
Exceptions
Type | Condition |
---|---|
System. |
The type being serialized does not conform to data contract rules. For example, the System. |
System. |
There is a problem with the instance being written. |
WriteObjectContent(XmlWriter, TDataContract)
Writes the XML content using an System.
Declaration
public void WriteObjectContent(XmlWriter writer, TDataContract graph)
Parameters
Type | Name | Description |
---|---|---|
System. |
writer | The System. |
TData |
graph | The object to write to the stream. |
Exceptions
Type | Condition |
---|---|
System. |
The type being serialized does not conform to data contract rules. For example, the System. |
System. |
There is a problem with the instance being written. |
WriteStartObject(XmlDictionaryWriter, TDataContract)
Writes the opening XML element using an System.
Declaration
public void WriteStartObject(XmlDictionaryWriter writer, TDataContract graph)
Parameters
Type | Name | Description |
---|---|---|
System. |
writer | The System. |
TData |
graph | The object to write. |
WriteStartObject(XmlWriter, TDataContract)
Writes the opening XML element using an System.
Declaration
public void WriteStartObject(XmlWriter writer, TDataContract graph)
Parameters
Type | Name | Description |
---|---|---|
System. |
writer | The System. |
TData |
graph | The object to write. |