Export (0) Print
Expand All

NetDataContractSerializer Constructor (StreamingContext, Int32, Boolean, FormatterAssemblyStyle, ISurrogateSelector)

Initializes a new instance of the NetDataContractSerializer class with the supplied context data; in addition, specifies the maximum number of items in the object to be serialized, and parameters to specify whether extra data is ignored, the assembly loading method, and a surrogate selector.

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

'Declaration
Public Sub New ( _
	context As StreamingContext, _
	maxItemsInObjectGraph As Integer, _
	ignoreExtensionDataObject As Boolean, _
	assemblyFormat As FormatterAssemblyStyle, _
	surrogateSelector As ISurrogateSelector _
)

Parameters

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 ISurrogateSelector.

ExceptionCondition
ArgumentOutOfRangeException

maxItemsInObjectGraph value is less than 0.

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 using a StreamingContext. 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 Shared Sub Constructor5() 
    ' Create an instance of the StreamingContext to hold 
    ' context data. 
    Dim sc As New StreamingContext()

    ' Create an instance of a class that implements the  
    ' ISurrogateSelector interface. The implementation code 
    ' is not shown here. 
    Dim mySurrogateSelector As New MySelector()

    Dim ser As New System.Runtime.Serialization. _
    NetDataContractSerializer _
    (sc, _
     65536, _
     True, _
     FormatterAssemblyStyle.Simple, _
     mySurrogateSelector)

    ' Other code not shown. 
End Sub

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft