Export (0) Print
Expand All

DataContractSerializer.DataContractSerializer(Type, XmlDictionaryString, XmlDictionaryString, Generic IEnumerable) Constructor

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.

Namespace: System.Runtime.Serialization
Assembly: System.Runtime.Serialization (in system.runtime.serialization.dll)

public DataContractSerializer (
	Type type,
	XmlDictionaryString rootName,
	XmlDictionaryString rootNamespace,
	IEnumerable<Type> knownTypes
)
public DataContractSerializer (
	Type type, 
	XmlDictionaryString rootName, 
	XmlDictionaryString rootNamespace, 
	IEnumerable<Type> knownTypes
)
public function DataContractSerializer (
	type : Type, 
	rootName : XmlDictionaryString, 
	rootNamespace : XmlDictionaryString, 
	knownTypes : IEnumerable<Type>
)
Not applicable.

Parameters

type

A Type that specifies the type of the instances that will be serialized or deserialized.

rootName

An XmlDictionaryString that contains the root element name of the content.

rootNamespace

An XmlDictionaryString that contains the namespace of the root element.

knownTypes

A IEnumerable of Type that contains the known types that may be present in the object graph.

The following example creates an instance of the DataContractSerializer that specifies the type to serialize or deserialize as well as the XML name and namespace (as XmlDictionaryString objects) to read from or write to the XML document. The code also creates an instance of a IEnumerable to contain the known types used during serialization or deserialization.

public static void Constructor6()
{
    // Create a generic List of types and add the known types
    // to the collection.
    List<Type> knownTypeList = new List<Type>();
    knownTypeList.Add(typeof(PurchaseOrder));
    knownTypeList.Add(typeof(PurchaseOrderV3));

    // Create an XmlDictionary and add values to it.
    XmlDictionary d = new XmlDictionary();
    XmlDictionaryString name_value = d.Add("Customer");
    XmlDictionaryString ns_value = d.Add("http://www.contoso.com");

    DataContractSerializer ser =
        new DataContractSerializer(
        typeof(Person),
        name_value,
        ns_value,
        knownTypeList);

    // Other code not shown.
}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2015 Microsoft