다음을 통해 공유


XmlSerializer Constructor (Type, array<Type[])

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Initializes a new instance of the XmlSerializer class that can serialize objects of the specified type into XML documents and deserialize XML documents into objects of a specified type. If a property or field returns an array, the extraTypes parameter specifies objects that can be inserted into the array.

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

Syntax

'Declaration
Public Sub New ( _
    type As Type, _
    extraTypes As Type() _
)
public XmlSerializer(
    Type type,
    Type[] extraTypes
)

Parameters

  • extraTypes
    Type: array<System.Type[]
    A Type array of additional object types to serialize.

Remarks

By default, if a public property or field returns an object or array of objects, the object types are automatically serialized. However, if a class contains a field or property that returns an array of type Object, any object can be inserted into that array. In that case, the XmlSerializer must be instructed to expect all the possible object types that are inserted into the Object array. To do this, use the extraTypes parameter to specify the extra object types to serialize or deserialize.

You can also use the extraTypes parameter to specify types derived from a base class. For example, suppose a base class named Phone exists and a class named InternationalPhone derives from it. Use the extraTypes parameter to specify the derived type as well.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.