Show / Hide Table of Contents

Class XmlSerializer

Class to serialize objects in a Xml-format.

Inheritance
object
XmlSerializer
XmiSerializer
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: NMF.Serialization
Assembly: NMF.Serialization.dll
Syntax
public class XmlSerializer

Constructors

| Edit this page View Source

XmlSerializer()

Creates a new XmlSerializer with default settings and no preloaded types

Declaration
public XmlSerializer()
| Edit this page View Source

XmlSerializer(XmlSerializationSettings)

Creates a new XmlSerializer with the specified settings

Declaration
public XmlSerializer(XmlSerializationSettings settings)
Parameters
Type Name Description
XmlSerializationSettings settings

Serializer-settings for the serializer. Can be null or Nothing in Visual Basic. In this case, the default settings will be used.

| Edit this page View Source

XmlSerializer(XmlSerializationSettings, IEnumerable<Type>)

Creates a new XmlSerializer with the specified settings and the given preloaded types

Declaration
public XmlSerializer(XmlSerializationSettings settings, IEnumerable<Type> additionalTypes)
Parameters
Type Name Description
XmlSerializationSettings settings

The settings to use for the serializer

IEnumerable<Type> additionalTypes

Set of types to load into the serializer

Remarks

The types will be loaded with the specified settings

| Edit this page View Source

XmlSerializer(XmlSerializer)

Creates a new XmlSerializer and copies settings and known types from the given serializer

Declaration
public XmlSerializer(XmlSerializer parent)
Parameters
Type Name Description
XmlSerializer parent

An XML serializer to copy settings and known type information from

| Edit this page View Source

XmlSerializer(XmlSerializer, XmlSerializationSettings)

Creates a new XmlSerializer and copies settings and known types from the given serializer

Declaration
public XmlSerializer(XmlSerializer parent, XmlSerializationSettings settings)
Parameters
Type Name Description
XmlSerializer parent

An XML serializer to copy settings and known type information from

XmlSerializationSettings settings

New settings

| Edit this page View Source

XmlSerializer(XmlSerializer, XmlSerializationSettings, IEnumerable<Type>)

Creates a new XmlSerializer and copies settings and known types from the given serializer

Declaration
public XmlSerializer(XmlSerializer parent, XmlSerializationSettings settings, IEnumerable<Type> additionalTypes)
Parameters
Type Name Description
XmlSerializer parent

An XML serializer to copy settings and known type information from

XmlSerializationSettings settings

New settings

IEnumerable<Type> additionalTypes

Set of types to load into the serializer

| Edit this page View Source

XmlSerializer(IEnumerable<Type>)

Creates a new XmlSerializer with default settings

Declaration
public XmlSerializer(IEnumerable<Type> additionalTypes)
Parameters
Type Name Description
IEnumerable<Type> additionalTypes

Set of types to preload into the serializer

Remarks

Types will be loaded with default settings

Properties

| Edit this page View Source

KnownTypes

The set of types that are known to the serializer

Declaration
public ICollection<Type> KnownTypes { get; }
Property Value
Type Description
ICollection<Type>
| Edit this page View Source

Settings

The settings to be used in the serializer

Declaration
public XmlSerializationSettings Settings { get; }
Property Value
Type Description
XmlSerializationSettings

Methods

| Edit this page View Source

CreateObject(XmlReader, ITypeSerializationInfo, XmlSerializationContext)

Creates the object for the current position

Declaration
protected virtual object CreateObject(XmlReader reader, ITypeSerializationInfo tsi, XmlSerializationContext context)
Parameters
Type Name Description
XmlReader reader

the xml reader

ITypeSerializationInfo tsi

the type serialization information

XmlSerializationContext context

the serialization context

Returns
Type Description
object

the deserialized object

| Edit this page View Source

CreateRoot(XmlReader)

Creates the root element

Declaration
protected object CreateRoot(XmlReader reader)
Parameters
Type Name Description
XmlReader reader

The xml reader

Returns
Type Description
object

The root element

| Edit this page View Source

CreateSerializationContext(object)

Creates a serialization context for the given root element

Declaration
protected virtual XmlSerializationContext CreateSerializationContext(object root)
Parameters
Type Name Description
object root

The root element of the serialization

Returns
Type Description
XmlSerializationContext

A serialization context

| Edit this page View Source

CreateTypeSerializationInfoFor(Type)

Creates the type serialization information for the given type

Declaration
protected virtual ITypeSerializationInfo CreateTypeSerializationInfoFor(Type type)
Parameters
Type Name Description
Type type

the system type for which the serialization information should be created

Returns
Type Description
ITypeSerializationInfo

a type serialization info

| Edit this page View Source

Deserialize(Stream)

Deserializes an Xml-representation of an object back to the corresponding object

Declaration
public object Deserialize(Stream stream)
Parameters
Type Name Description
Stream stream

The stream containg the Xml code

Returns
Type Description
object

The corresponding object

| Edit this page View Source

Deserialize(TextReader)

Deserializes an Xml-representation of an object back to the corresponding object

Declaration
public object Deserialize(TextReader reader)
Parameters
Type Name Description
TextReader reader

A TextReader containg the Xml code

Returns
Type Description
object

The corresponding object

| Edit this page View Source

Deserialize(string)

Deserializes an Xml-representation of an object back to the corresponding object

Declaration
public object Deserialize(string path)
Parameters
Type Name Description
string path

The path to the Xml file containg the Xml code

Returns
Type Description
object

The corresponding object

| Edit this page View Source

Deserialize(XmlReader)

Deserializes an Xml-representation of an object back to the corresponding object

Declaration
public object Deserialize(XmlReader reader)
Parameters
Type Name Description
XmlReader reader

A XmlReader containing the Xml code

Returns
Type Description
object

The corresponding object

Remarks

The function will deserialize the object at the XmlReaders current position

| Edit this page View Source

GetAttributeValue(object, ITypeSerializationInfo, bool, XmlSerializationContext)

Gets the serialization of the given attribute value

Declaration
protected virtual string GetAttributeValue(object value, ITypeSerializationInfo info, bool isCollection, XmlSerializationContext context)
Parameters
Type Name Description
object value

The value of the attribute

ITypeSerializationInfo info

The serialization information of the type

bool isCollection

True, if the value is added to a collection, otherwise false

XmlSerializationContext context

The serialization context

Returns
Type Description
string

The serialized value of the attribute

| Edit this page View Source

GetElementTypeInfo(XmlReader, IPropertySerializationInfo)

Gets the type information for the current property

Declaration
protected virtual ITypeSerializationInfo GetElementTypeInfo(XmlReader reader, IPropertySerializationInfo property)
Parameters
Type Name Description
XmlReader reader

The xml reader

IPropertySerializationInfo property

The current property

Returns
Type Description
ITypeSerializationInfo

The type serialization info that should be used in the remainder

| Edit this page View Source

GetRootElementTypeInfo(XmlReader)

Gets the type information for the root element

Declaration
protected virtual ITypeSerializationInfo GetRootElementTypeInfo(XmlReader reader)
Parameters
Type Name Description
XmlReader reader

The xml reader

Returns
Type Description
ITypeSerializationInfo

The type serialization info for the root element

| Edit this page View Source

GetSerializationInfo(Type, bool)

Gets the serialization information for the given type

Declaration
public ITypeSerializationInfo GetSerializationInfo(Type type, bool createIfNecessary)
Parameters
Type Name Description
Type type

The type

bool createIfNecessary

If true, the serialization information is added if missing

Returns
Type Description
ITypeSerializationInfo

The type serialization information

| Edit this page View Source

GetSerializationInfoForInstance(object, bool)

Gets the serialization information for the provided instance

Declaration
public virtual ITypeSerializationInfo GetSerializationInfoForInstance(object instance, bool createIfNecessary)
Parameters
Type Name Description
object instance

The instance

bool createIfNecessary

If true, the serialization information is added if missing

Returns
Type Description
ITypeSerializationInfo

The type serialization information

| Edit this page View Source

GetTypeInfo(string, string)

Gets the type serialization info corresponding to the provided pair of namespace and local name

Declaration
public ITypeSerializationInfo GetTypeInfo(string ns, string localName)
Parameters
Type Name Description
string ns

the namespace of the type

string localName

the local name of the type

Returns
Type Description
ITypeSerializationInfo

the type serialization info

| Edit this page View Source

GoToPropertyContent(XmlReader)

Moves the reader to the content of the property

Declaration
protected virtual bool GoToPropertyContent(XmlReader reader)
Parameters
Type Name Description
XmlReader reader

the Xml reader

Returns
Type Description
bool

true, if the reader could be moved sucessfully, otherwise false

| Edit this page View Source

HandleUnknownAttribute(XmlReader, object, ITypeSerializationInfo, XmlSerializationContext)

Handles an attribute that was not known to the serializer

Declaration
protected virtual void HandleUnknownAttribute(XmlReader reader, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
Type Name Description
XmlReader reader

The current reader position

object obj

The object that is currently deserialized

ITypeSerializationInfo info

The type serialization information of the object

XmlSerializationContext context

The serialization context

| Edit this page View Source

HandleUnknownElement(XmlReader, object, ITypeSerializationInfo, XmlSerializationContext)

Handles an element that was not known to the serializer

Declaration
protected virtual void HandleUnknownElement(XmlReader reader, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
Type Name Description
XmlReader reader

The current reader position

object obj

The object that is currently deserialized

ITypeSerializationInfo info

The type serialization information of the object

XmlSerializationContext context

The serialization context

| Edit this page View Source

HandleUnknownType(IPropertySerializationInfo, string, string)

Handles the case that the type of the element is not known

Declaration
protected virtual ITypeSerializationInfo HandleUnknownType(IPropertySerializationInfo property, string ns, string localName)
Parameters
Type Name Description
IPropertySerializationInfo property

The property for which the type was requested

string ns

The namespace at the current position

string localName

The local name of the type

Returns
Type Description
ITypeSerializationInfo

The type serialization information received for this type or null, if no type could be resolved

| Edit this page View Source

Initialize(XmlReader, object, XmlSerializationContext)

Initializes the given object with the xml code at the current position of the XmlReader

Declaration
public void Initialize(XmlReader reader, object obj, XmlSerializationContext context)
Parameters
Type Name Description
XmlReader reader

The XmlReader with the Xml code

object obj

The object to initialize

XmlSerializationContext context

The serialization context

| Edit this page View Source

InitializeAttributeProperties(XmlReader, object, ITypeSerializationInfo, XmlSerializationContext)

Initializes the attribute properties from the current reader position

Declaration
protected virtual void InitializeAttributeProperties(XmlReader reader, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
Type Name Description
XmlReader reader

the xml reader

object obj

the object

ITypeSerializationInfo info

the type serialization information

XmlSerializationContext context

the serialization context

| Edit this page View Source

InitializeElementProperties(XmlReader, ref object, ITypeSerializationInfo, XmlSerializationContext)

Initializes the element properties from the xml reader position

Declaration
protected virtual void InitializeElementProperties(XmlReader reader, ref object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
Type Name Description
XmlReader reader

the xml reader

object obj

the element

ITypeSerializationInfo info

the type serialization information

XmlSerializationContext context

the serialization context

| Edit this page View Source

InitializeProperty(XmlReader, IPropertySerializationInfo, object, XmlSerializationContext)

Initialized the property from the reader

Declaration
protected virtual bool InitializeProperty(XmlReader reader, IPropertySerializationInfo property, object obj, XmlSerializationContext context)
Parameters
Type Name Description
XmlReader reader

the xml reader

IPropertySerializationInfo property

the property

object obj

the object

XmlSerializationContext context

the serialization context

Returns
Type Description
bool

true, if the initialization was successful, otherwise false

| Edit this page View Source

InitializePropertyFromText(IPropertySerializationInfo, object, string, XmlSerializationContext)

Initializes the given property from the provided text

Declaration
protected virtual void InitializePropertyFromText(IPropertySerializationInfo property, object obj, string text, XmlSerializationContext context)
Parameters
Type Name Description
IPropertySerializationInfo property

The property

object obj

The object

string text

The input text

XmlSerializationContext context

The serialization context

| Edit this page View Source

InitializeTypeSerializationInfo(Type, ITypeSerializationInfo)

Initializes the given type serialization information for the given type

Declaration
protected virtual void InitializeTypeSerializationInfo(Type type, ITypeSerializationInfo serializationInfo)
Parameters
Type Name Description
Type type

the system type

ITypeSerializationInfo serializationInfo

the serialization information object

| Edit this page View Source

IsPropertyElement(XmlReader, IPropertySerializationInfo)

Determines whether the element at the current reader position refers to the given property

Declaration
protected virtual bool IsPropertyElement(XmlReader reader, IPropertySerializationInfo property)
Parameters
Type Name Description
XmlReader reader

The reader position

IPropertySerializationInfo property

The property that should be tested

Returns
Type Description
bool

true, if the element is about the property, otherwise false

| Edit this page View Source

OnUnknownAttribute(UnknownAttributeEventArgs)

Fires the UnknownAttribute event

Declaration
protected virtual void OnUnknownAttribute(UnknownAttributeEventArgs e)
Parameters
Type Name Description
UnknownAttributeEventArgs e

the event data

| Edit this page View Source

OnUnknownElement(UnknownElementEventArgs)

Fires the UnknownElement event

Declaration
protected virtual void OnUnknownElement(UnknownElementEventArgs e)
Parameters
Type Name Description
UnknownElementEventArgs e

the event data

| Edit this page View Source

OnUnknownType(UnknownTypeEventArgs)

Handles the UnknownType event

Declaration
protected virtual void OnUnknownType(UnknownTypeEventArgs e)
Parameters
Type Name Description
UnknownTypeEventArgs e

the event data

| Edit this page View Source

OverrideIdentifiedObject(object, XmlReader, XmlSerializationContext)

Determines whether the already identified element should be overridden

Declaration
protected virtual bool OverrideIdentifiedObject(object obj, XmlReader reader, XmlSerializationContext context)
Parameters
Type Name Description
object obj

The object that would be overridden

XmlReader reader

The current reader position

XmlSerializationContext context

The serialization context

Returns
Type Description
bool

true, if the element shall be overridden, otherwise false

| Edit this page View Source

RegisterNamespace(ITypeSerializationInfo)

Registers the given type serialization info for a namespace lookup

Declaration
protected void RegisterNamespace(ITypeSerializationInfo info)
Parameters
Type Name Description
ITypeSerializationInfo info

the type serialization info

| Edit this page View Source

SelectRoot(object, bool)

Gets the serialization root element

Declaration
protected virtual object SelectRoot(object graph, bool fragment)
Parameters
Type Name Description
object graph

The base element that should be serialized

bool fragment

A value indicating whether only a fragment should be written

Returns
Type Description
object

The root element for serialization

| Edit this page View Source

Serialize(object, Stream, bool)

Serializes the given object

Declaration
public void Serialize(object source, Stream stream, bool fragment = false)
Parameters
Type Name Description
object source

The object to be serialized

Stream stream

The stream for the resulting Xml-code

bool fragment

A value that indicates whether the serializer should write a document definition

| Edit this page View Source

Serialize(object, TextWriter)

Serializes the given object

Declaration
public void Serialize(object source, TextWriter writer)
Parameters
Type Name Description
object source

The object to be serialized

TextWriter writer

The TextWriter to write the Xml-code on

| Edit this page View Source

Serialize(object, TextWriter, bool)

Serializes the given object

Declaration
public void Serialize(object source, TextWriter target, bool fragment)
Parameters
Type Name Description
object source

The object to be serialized

TextWriter target

The TextWriter to write the Xml-code on

bool fragment

A value that indicates whether the serializer should write a document definition

| Edit this page View Source

Serialize(object, string, bool)

Serializes the given object

Declaration
public void Serialize(object obj, string path, bool fragment = false)
Parameters
Type Name Description
object obj

The object to be serialized

string path

The path for the resulting Xml-file

bool fragment

A value that indicates whether the serializer should write a document definition

| Edit this page View Source

Serialize(object, XmlWriter)

Serializes the given object

Declaration
public void Serialize(object source, XmlWriter writer)
Parameters
Type Name Description
object source

The object to be serialized

XmlWriter writer

The XmlWriter to write the Xml-code on

| Edit this page View Source

Serialize(object, XmlWriter, IPropertySerializationInfo, bool, XmlIdentificationMode, XmlSerializationContext)

Serializes the given object

Declaration
public virtual void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)
Parameters
Type Name Description
object obj

The object to be serialized

XmlWriter writer

The XmlWriter to write the Xml-code on

IPropertySerializationInfo property

The property for which the object is serialized

bool writeInstance

A value that indicates whether the serializer should write the element definition

XmlIdentificationMode identificationMode

A value indicating whether it is allowed to the serializer to use identifier

XmlSerializationContext context

The serialization context

Remarks

If a converter is provided that is able to convert the object to string and convert the string back to this object, just the string-conversion is printed out

| Edit this page View Source

Serialize(object, XmlWriter, bool)

Serializes the given object

Declaration
public void Serialize(object source, XmlWriter target, bool fragment)
Parameters
Type Name Description
object source

The object to be serialized

XmlWriter target

The XmlWriter to write the Xml-code on

bool fragment

A value that indicates whether the serializer should write a document definition

| Edit this page View Source

WriteAttributeProperties(XmlWriter, object, ITypeSerializationInfo, XmlSerializationContext)

Writes the attribute properties of the given object

Declaration
protected virtual void WriteAttributeProperties(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object obj

The element

ITypeSerializationInfo info

The serialization information of the objects type

XmlSerializationContext context

The serialization context

| Edit this page View Source

WriteAttributeValue(XmlWriter, object, object, IPropertySerializationInfo, XmlSerializationContext)

Writes the attribute value to the given writer

Declaration
protected virtual void WriteAttributeValue(XmlWriter writer, object obj, object value, IPropertySerializationInfo property, XmlSerializationContext context)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object obj

The element

object value

The value of the attribute

IPropertySerializationInfo property

The property serialization information

XmlSerializationContext context

The serialization context

| Edit this page View Source

WriteBeginElement(XmlWriter, object, ITypeSerializationInfo)

Writes the beginning of an element

Declaration
protected virtual void WriteBeginElement(XmlWriter writer, object obj, ITypeSerializationInfo info)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object obj

The element

ITypeSerializationInfo info

The serialization information of the objects type

| Edit this page View Source

WriteBeginRootElement(XmlWriter, object, ITypeSerializationInfo)

Writes the root element to the given writer

Declaration
protected virtual void WriteBeginRootElement(XmlWriter writer, object root, ITypeSerializationInfo info)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object root

The root element

ITypeSerializationInfo info

The serialization information of the objects type

| Edit this page View Source

WriteCollectionMembers(XmlWriter, object, ITypeSerializationInfo, XmlSerializationContext)

Writes the elements of the given collection to the provided writer

Declaration
protected virtual void WriteCollectionMembers(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object obj

The element

ITypeSerializationInfo info

The serialization information of the objects type

XmlSerializationContext context

The serialization context

| Edit this page View Source

WriteConstructorProperties(XmlWriter, object, ITypeSerializationInfo, XmlSerializationContext)

Writes the properties necessary for the constrctor call of this element

Declaration
protected virtual void WriteConstructorProperties(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object obj

The element

ITypeSerializationInfo info

The serialization information of the objects type

XmlSerializationContext context

The serialization context

| Edit this page View Source

WriteElementProperties(XmlWriter, object, ITypeSerializationInfo, XmlSerializationContext)

Writes the element properties of the given object to the provided writer

Declaration
protected virtual void WriteElementProperties(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object obj

The element

ITypeSerializationInfo info

The serialization information of the objects type

XmlSerializationContext context

The serialization context

| Edit this page View Source

WriteEndElement(XmlWriter, object, ITypeSerializationInfo)

Completes the current element for the provided object

Declaration
protected virtual void WriteEndElement(XmlWriter writer, object obj, ITypeSerializationInfo info)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object obj

The element

ITypeSerializationInfo info

The serialization information of the objects type

| Edit this page View Source

WriteEndRootElement(XmlWriter, object, ITypeSerializationInfo)

Completes the root element

Declaration
protected virtual void WriteEndRootElement(XmlWriter writer, object root, ITypeSerializationInfo info)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object root

The element

ITypeSerializationInfo info

The serialization information of the objects type

| Edit this page View Source

WriteIdentifiedObject(XmlWriter, object, XmlIdentificationMode, ITypeSerializationInfo, XmlSerializationContext)

Writes the provided identified object

Declaration
protected virtual bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)
Parameters
Type Name Description
XmlWriter writer

The xml writer to write to

object obj

The element

XmlIdentificationMode identificationMode

The identification mode for the current object

ITypeSerializationInfo info

The serialization information of the objects type

XmlSerializationContext context

The serialization context

Returns
Type Description
bool

true, if the object could be written as identified object, otherwise false

Events

| Edit this page View Source

UnknownAttribute

Get raised when the serializer finds an attribute that is not known

Declaration
public event EventHandler<UnknownAttributeEventArgs> UnknownAttribute
Event Type
Type Description
EventHandler<UnknownAttributeEventArgs>
| Edit this page View Source

UnknownElement

Gets raised when the serializer finds an element that is not known

Declaration
public event EventHandler<UnknownElementEventArgs> UnknownElement
Event Type
Type Description
EventHandler<UnknownElementEventArgs>
| Edit this page View Source

UnknownType

Gets raised when the serializer finds a type that is not known

Declaration
public event EventHandler<UnknownTypeEventArgs> UnknownType
Event Type
Type Description
EventHandler<UnknownTypeEventArgs>
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX