Export (0) Print
Expand All

NetDataContractSerializer Constructor (XmlDictionaryString, XmlDictionaryString)

Initializes a new instance of the NetDataContractSerializer class with two parameters of type XmlDictionaryString that contain the root element and namespace used to specify the content.

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

public NetDataContractSerializer(
	XmlDictionaryString rootName,
	XmlDictionaryString rootNamespace
)

Parameters

rootName
Type: System.Xml.XmlDictionaryString

An XmlDictionaryString that contains the name of the XML element that encloses the content to serialize or deserialize.

rootNamespace
Type: System.Xml.XmlDictionaryString

An XmlDictionaryString that contains the namespace of the XML element that encloses the content to serialize or deserialize.

The XmlDictionaryString can be used to optimize performance when the same set of strings is used across object instances.

The following example creates an instance of the DataContractSerializer specifying the XML root element and namespace (as XmlDictionaryString arguments) it will expect when deserializing an object.

public static void Constructor4()
{
    // Create an XmlDictionary and add values to it.
    XmlDictionary d = new XmlDictionary();
    // Initialize the out variables.
    XmlDictionaryString name_value = d.Add("Customer");
    XmlDictionaryString ns_value = d.Add("http://www.contoso.com");

    // Create the serializer.
    NetDataContractSerializer ser =
        new NetDataContractSerializer(
        name_value,
        ns_value);
    // Other code not shown.
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft