NetDataContractSerializer Constructor (XmlDictionaryString, XmlDictionaryString, StreamingContext, Int32, Boolean, FormatterAssemblyStyle, ISurrogateSelector)
Initializes a new instance of the NetDataContractSerializer class with the supplied context data, and root name and namespace (as XmlDictionaryString parameters); in addition, specifies the maximum number of items in the object to be serialized, and parameters to specify whether extra data found is ignored, assembly loading method, and a surrogate selector.
Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)
public NetDataContractSerializer( XmlDictionaryString rootName, XmlDictionaryString rootNamespace, StreamingContext context, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, FormatterAssemblyStyle assemblyFormat, ISurrogateSelector surrogateSelector )
Parameters
- rootName
- Type: System.Xml.XmlDictionaryString
An XmlDictionaryString that contains the root element of the content.
- rootNamespace
- Type: System.Xml.XmlDictionaryString
An XmlDictionaryString that contains the namespace of the root element.
- context
- Type: System.Runtime.Serialization.StreamingContext
A StreamingContext that contains context data.
- maxItemsInObjectGraph
- Type: System.Int32
The maximum number of items in the graph to serialize or deserialize.
- ignoreExtensionDataObject
- Type: System.Boolean
true to ignore the data supplied by an extension of the type; otherwise, false.
- assemblyFormat
- Type: System.Runtime.Serialization.Formatters.FormatterAssemblyStyle
A FormatterAssemblyStyle enumeration value that specifies a method for locating and loading assemblies.
- surrogateSelector
- Type: System.Runtime.Serialization.ISurrogateSelector
An implementation of the IDataContractSurrogate to handle the legacy type.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | maxItemsInObjectGraph value is less than 0. |
The XmlDictionaryString can be used to optimize performance when the same set of strings is used across object instances.
The ignoreExtensionDataObject parameter is used when the IExtensibleDataObject interface is implemented in the class that is being serialized or deserialized.
The following example creates an instance of the NetDataContractSerializer specifying the XML element name and namespace (as XmlDictionaryString arguments) to expect when deserializing. The code also sets the ignoreExtensionDataObject, and specifies an implementation of the ISurrogateSelector interface to handle to assist the serializer when selecting a surrogate (for deserializing legacy types).
public static void Constructor7() { // Create an instance of the StreamingContext to hold // context data. StreamingContext sc = new StreamingContext (StreamingContextStates.CrossAppDomain); // 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"); // Create an instance of a class that implements the // ISurrogateSelector interface. The implementation code // is not shown here. MySelector mySurrogateSelector = new MySelector(); NetDataContractSerializer ser = new NetDataContractSerializer( name_value, ns_value, sc, int.MaxValue, true, FormatterAssemblyStyle.Simple, mySurrogateSelector); // Other code not shown. }
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.