Table of Contents

Class XmlSerializer

Namespace
NMF.Serialization
Assembly
NMF.Serialization.dll

Class to serialize objects in a Xml-format.

public class XmlSerializer : Serializer
Inheritance
XmlSerializer
Derived
Inherited Members

Constructors

XmlSerializer()

Creates a new XmlSerializer with default settings and no preloaded types

public XmlSerializer()

XmlSerializer(XmlSerializationSettings)

Creates a new XmlSerializer with the specified settings

public XmlSerializer(XmlSerializationSettings settings)

Parameters

settings XmlSerializationSettings

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

XmlSerializer(XmlSerializationSettings, IEnumerable<Type>)

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

public XmlSerializer(XmlSerializationSettings settings, IEnumerable<Type> additionalTypes)

Parameters

settings XmlSerializationSettings

The settings to use for the serializer

additionalTypes IEnumerable<Type>

Set of types to load into the serializer

Remarks

The types will be loaded with the specified settings

XmlSerializer(XmlSerializer)

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

public XmlSerializer(XmlSerializer parent)

Parameters

parent XmlSerializer

An XML serializer to copy settings and known type information from

XmlSerializer(XmlSerializer, XmlSerializationSettings)

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

public XmlSerializer(XmlSerializer parent, XmlSerializationSettings settings)

Parameters

parent XmlSerializer

An XML serializer to copy settings and known type information from

settings XmlSerializationSettings

New settings

XmlSerializer(XmlSerializer, XmlSerializationSettings, IEnumerable<Type>)

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

public XmlSerializer(XmlSerializer parent, XmlSerializationSettings settings, IEnumerable<Type> additionalTypes)

Parameters

parent XmlSerializer

An XML serializer to copy settings and known type information from

settings XmlSerializationSettings

New settings

additionalTypes IEnumerable<Type>

Set of types to load into the serializer

XmlSerializer(IEnumerable<Type>)

Creates a new XmlSerializer with default settings

public XmlSerializer(IEnumerable<Type> additionalTypes)

Parameters

additionalTypes IEnumerable<Type>

Set of types to preload into the serializer

Remarks

Types will be loaded with default settings

Methods

CreateObject(XmlReader, ITypeSerializationInfo, XmlSerializationContext)

Creates the object for the current position

protected virtual object CreateObject(XmlReader reader, ITypeSerializationInfo tsi, XmlSerializationContext context)

Parameters

reader XmlReader

the xml reader

tsi ITypeSerializationInfo

the type serialization information

context XmlSerializationContext

the serialization context

Returns

object

the deserialized object

CreateRoot(XmlReader)

Creates the root element

protected object CreateRoot(XmlReader reader)

Parameters

reader XmlReader

The xml reader

Returns

object

The root element

Deserialize(Stream)

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

public object Deserialize(Stream stream)

Parameters

stream Stream

The stream containg the Xml code

Returns

object

The corresponding object

Deserialize(TextReader)

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

public object Deserialize(TextReader reader)

Parameters

reader TextReader

A TextReader containg the Xml code

Returns

object

The corresponding object

Deserialize(string)

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

public object Deserialize(string path)

Parameters

path string

The path to the Xml file containg the Xml code

Returns

object

The corresponding object

Deserialize(XmlReader)

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

public object Deserialize(XmlReader reader)

Parameters

reader XmlReader

A XmlReader containing the Xml code

Returns

object

The corresponding object

Remarks

The function will deserialize the object at the XmlReaders current position

GetElementTypeInfo(XmlReader, IPropertySerializationInfo)

Gets the type information for the current property

protected virtual ITypeSerializationInfo GetElementTypeInfo(XmlReader reader, IPropertySerializationInfo property)

Parameters

reader XmlReader

The xml reader

property IPropertySerializationInfo

The current property

Returns

ITypeSerializationInfo

The type serialization info that should be used in the remainder

GetRootElementTypeInfo(XmlReader)

Gets the type information for the root element

protected virtual ITypeSerializationInfo GetRootElementTypeInfo(XmlReader reader)

Parameters

reader XmlReader

The xml reader

Returns

ITypeSerializationInfo

The type serialization info for the root element

GoToPropertyContent(XmlReader)

Moves the reader to the content of the property

protected virtual bool GoToPropertyContent(XmlReader reader)

Parameters

reader XmlReader

the Xml reader

Returns

bool

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

HandleUnknownAttribute(XmlReader, object, ITypeSerializationInfo, XmlSerializationContext)

Handles an attribute that was not known to the serializer

protected virtual void HandleUnknownAttribute(XmlReader reader, object obj, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

reader XmlReader

The current reader position

obj object

The object that is currently deserialized

info ITypeSerializationInfo

The type serialization information of the object

context XmlSerializationContext

The serialization context

HandleUnknownElement(XmlReader, object, ITypeSerializationInfo, XmlSerializationContext)

Handles an element that was not known to the serializer

protected virtual void HandleUnknownElement(XmlReader reader, object obj, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

reader XmlReader

The current reader position

obj object

The object that is currently deserialized

info ITypeSerializationInfo

The type serialization information of the object

context XmlSerializationContext

The serialization context

Initialize(XmlReader, object, XmlSerializationContext)

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

public void Initialize(XmlReader reader, object obj, XmlSerializationContext context)

Parameters

reader XmlReader

The XmlReader with the Xml code

obj object

The object to initialize

context XmlSerializationContext

The serialization context

InitializeAttributeProperties(XmlReader, object, ITypeSerializationInfo, XmlSerializationContext)

Initializes the attribute properties from the current reader position

protected virtual void InitializeAttributeProperties(XmlReader reader, object obj, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

reader XmlReader

the xml reader

obj object

the object

info ITypeSerializationInfo

the type serialization information

context XmlSerializationContext

the serialization context

InitializeElementProperties(XmlReader, ref object, ITypeSerializationInfo, XmlSerializationContext)

Initializes the element properties from the xml reader position

protected virtual void InitializeElementProperties(XmlReader reader, ref object obj, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

reader XmlReader

the xml reader

obj object

the element

info ITypeSerializationInfo

the type serialization information

context XmlSerializationContext

the serialization context

InitializeProperty(XmlReader, IPropertySerializationInfo, object, XmlSerializationContext)

Initialized the property from the reader

protected virtual bool InitializeProperty(XmlReader reader, IPropertySerializationInfo property, object obj, XmlSerializationContext context)

Parameters

reader XmlReader

the xml reader

property IPropertySerializationInfo

the property

obj object

the object

context XmlSerializationContext

the serialization context

Returns

bool

true, if the initialization was successful, otherwise false

InitializePropertyFromText(IPropertySerializationInfo, object, string, XmlSerializationContext)

Initializes the given property from the provided text

protected virtual void InitializePropertyFromText(IPropertySerializationInfo property, object obj, string text, XmlSerializationContext context)

Parameters

property IPropertySerializationInfo

The property

obj object

The object

text string

The input text

context XmlSerializationContext

The serialization context

IsPropertyElement(XmlReader, IPropertySerializationInfo)

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

protected virtual bool IsPropertyElement(XmlReader reader, IPropertySerializationInfo property)

Parameters

reader XmlReader

The reader position

property IPropertySerializationInfo

The property that should be tested

Returns

bool

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

OverrideIdentifiedObject(object, XmlReader, XmlSerializationContext)

Determines whether the already identified element should be overridden

protected virtual bool OverrideIdentifiedObject(object obj, XmlReader reader, XmlSerializationContext context)

Parameters

obj object

The object that would be overridden

reader XmlReader

The current reader position

context XmlSerializationContext

The serialization context

Returns

bool

true, if the element shall be overridden, otherwise false

Serialize(object, Stream, bool)

Serializes the given object

public void Serialize(object source, Stream stream, bool fragment = false)

Parameters

source object

The object to be serialized

stream Stream

The stream for the resulting Xml-code

fragment bool

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

Serialize(object, TextWriter)

Serializes the given object

public void Serialize(object source, TextWriter writer)

Parameters

source object

The object to be serialized

writer TextWriter

The TextWriter to write the Xml-code on

Serialize(object, TextWriter, bool)

Serializes the given object

public void Serialize(object source, TextWriter target, bool fragment)

Parameters

source object

The object to be serialized

target TextWriter

The TextWriter to write the Xml-code on

fragment bool

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

Serialize(object, string, bool)

Serializes the given object

public void Serialize(object obj, string path, bool fragment = false)

Parameters

obj object

The object to be serialized

path string

The path for the resulting Xml-file

fragment bool

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

Serialize(object, XmlWriter)

Serializes the given object

public void Serialize(object source, XmlWriter writer)

Parameters

source object

The object to be serialized

writer XmlWriter

The XmlWriter to write the Xml-code on

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

Serializes the given object

public virtual void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)

Parameters

obj object

The object to be serialized

writer XmlWriter

The XmlWriter to write the Xml-code on

property IPropertySerializationInfo

The property for which the object is serialized

writeInstance bool

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

identificationMode XmlIdentificationMode

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

context XmlSerializationContext

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

Serialize(object, XmlWriter, bool)

Serializes the given object

public void Serialize(object source, XmlWriter target, bool fragment)

Parameters

source object

The object to be serialized

target XmlWriter

The XmlWriter to write the Xml-code on

fragment bool

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

WriteAttributeProperties(XmlWriter, object, ITypeSerializationInfo, XmlSerializationContext)

Writes the attribute properties of the given object

protected virtual void WriteAttributeProperties(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

writer XmlWriter

The xml writer to write to

obj object

The element

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The serialization context

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

Writes the attribute value to the given writer

protected virtual void WriteAttributeValue(XmlWriter writer, object obj, object value, IPropertySerializationInfo property, XmlSerializationContext context)

Parameters

writer XmlWriter

The xml writer to write to

obj object

The element

value object

The value of the attribute

property IPropertySerializationInfo

The property serialization information

context XmlSerializationContext

The serialization context

WriteBeginElement(XmlWriter, object, ITypeSerializationInfo)

Writes the beginning of an element

protected virtual void WriteBeginElement(XmlWriter writer, object obj, ITypeSerializationInfo info)

Parameters

writer XmlWriter

The xml writer to write to

obj object

The element

info ITypeSerializationInfo

The serialization information of the objects type

WriteBeginRootElement(XmlWriter, object, ITypeSerializationInfo)

Writes the root element to the given writer

protected virtual void WriteBeginRootElement(XmlWriter writer, object root, ITypeSerializationInfo info)

Parameters

writer XmlWriter

The xml writer to write to

root object

The root element

info ITypeSerializationInfo

The serialization information of the objects type

WriteCollectionMembers(XmlWriter, object, ITypeSerializationInfo, XmlSerializationContext)

Writes the elements of the given collection to the provided writer

protected virtual void WriteCollectionMembers(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

writer XmlWriter

The xml writer to write to

obj object

The element

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The serialization context

WriteConstructorProperties(XmlWriter, object, ITypeSerializationInfo, XmlSerializationContext)

Writes the properties necessary for the constrctor call of this element

protected virtual void WriteConstructorProperties(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

writer XmlWriter

The xml writer to write to

obj object

The element

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The serialization context

WriteElementProperties(XmlWriter, object, ITypeSerializationInfo, XmlSerializationContext)

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

protected virtual void WriteElementProperties(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

writer XmlWriter

The xml writer to write to

obj object

The element

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The serialization context

WriteEndElement(XmlWriter, object, ITypeSerializationInfo)

Completes the current element for the provided object

protected virtual void WriteEndElement(XmlWriter writer, object obj, ITypeSerializationInfo info)

Parameters

writer XmlWriter

The xml writer to write to

obj object

The element

info ITypeSerializationInfo

The serialization information of the objects type

WriteEndRootElement(XmlWriter, object, ITypeSerializationInfo)

Completes the root element

protected virtual void WriteEndRootElement(XmlWriter writer, object root, ITypeSerializationInfo info)

Parameters

writer XmlWriter

The xml writer to write to

root object

The element

info ITypeSerializationInfo

The serialization information of the objects type

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

Writes the provided identified object

protected virtual bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)

Parameters

writer XmlWriter

The xml writer to write to

obj object

The element

identificationMode XmlIdentificationMode

The identification mode for the current object

info ITypeSerializationInfo

The serialization information of the objects type

context XmlSerializationContext

The serialization context

Returns

bool

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