XmlSerializer Constructor (Type, XmlAttributeOverrides, array<Type[], XmlRootAttribute, String)
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 type Object into XML document instances and deserialize XML document instances into objects of type Object. Each object to be serialized can itself contain instances of classes, which this overload overrides with other classes. This overload also specifies the default namespace for all the XML elements and the class to use as the XML root element.
Namespace: System.Xml.Serialization
Assembly: System.Xml.Serialization (in System.Xml.Serialization.dll)
Syntax
'Declaration
Public Sub New ( _
type As Type, _
overrides As XmlAttributeOverrides, _
extraTypes As Type(), _
root As XmlRootAttribute, _
defaultNamespace As String _
)
public XmlSerializer(
Type type,
XmlAttributeOverrides overrides,
Type[] extraTypes,
XmlRootAttribute root,
string defaultNamespace
)
Parameters
- type
Type: System.Type
The type of the object that this XmlSerializer can serialize.
- overrides
Type: System.Xml.Serialization.XmlAttributeOverrides
An XmlAttributeOverrides that extends or overrides the behavior of the class specified in the type parameter.
- extraTypes
Type: array<System.Type[]
A Type array of additional object types to serialize.
- root
Type: System.Xml.Serialization.XmlRootAttribute
An XmlRootAttribute that defines the XML root element properties.
- defaultNamespace
Type: System.String
The default namespace of all XML elements in the XML document.
Remarks
The overrides parameter allows for the creation of an XmlSerializer that serializes a class that extends or overrides the behavior of a base class. For example, given a DLL, it is possible to create a class that inherits or extends a class contained in the DLL. To serialize such a class, you must use an instance of the XmlAttributeOverrides class when constructing the XmlSerializer.
For more information, see
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.
The root element of an XML document encloses all the other elements. By default, the object specified by the type parameter is serialized as the root element. Properties, such as the XML element name of the root element are taken from the type object. However, the root parameter allows you to replace the default object's information by specifying an XmlRootAttribute. The object allows you to set a different namespace, element name, and so on.
Use the defaultName parameter to specify the default namespace of all XML elements generated by the XmlSerializer.
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.