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
settingsXmlSerializationSettingsSerializer-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
settingsXmlSerializationSettingsThe settings to use for the serializer
additionalTypesIEnumerable<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
parentXmlSerializerAn 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
parentXmlSerializerAn XML serializer to copy settings and known type information from
settingsXmlSerializationSettingsNew 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
parentXmlSerializerAn XML serializer to copy settings and known type information from
settingsXmlSerializationSettingsNew settings
additionalTypesIEnumerable<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
additionalTypesIEnumerable<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
readerXmlReaderthe xml reader
tsiITypeSerializationInfothe type serialization information
contextXmlSerializationContextthe serialization context
Returns
- object
the deserialized object
CreateRoot(XmlReader)
Creates the root element
protected object CreateRoot(XmlReader reader)
Parameters
readerXmlReaderThe 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
streamStreamThe 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
readerTextReaderA 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
pathstringThe 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
readerXmlReaderA 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
readerXmlReaderThe xml reader
propertyIPropertySerializationInfoThe 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
readerXmlReaderThe 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
readerXmlReaderthe 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
readerXmlReaderThe current reader position
objobjectThe object that is currently deserialized
infoITypeSerializationInfoThe type serialization information of the object
contextXmlSerializationContextThe 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
readerXmlReaderThe current reader position
objobjectThe object that is currently deserialized
infoITypeSerializationInfoThe type serialization information of the object
contextXmlSerializationContextThe 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
readerXmlReaderThe XmlReader with the Xml code
objobjectThe object to initialize
contextXmlSerializationContextThe 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
readerXmlReaderthe xml reader
objobjectthe object
infoITypeSerializationInfothe type serialization information
contextXmlSerializationContextthe 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
readerXmlReaderthe xml reader
objobjectthe element
infoITypeSerializationInfothe type serialization information
contextXmlSerializationContextthe 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
readerXmlReaderthe xml reader
propertyIPropertySerializationInfothe property
objobjectthe object
contextXmlSerializationContextthe 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
propertyIPropertySerializationInfoThe property
objobjectThe object
textstringThe input text
contextXmlSerializationContextThe 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
readerXmlReaderThe reader position
propertyIPropertySerializationInfoThe 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
objobjectThe object that would be overridden
readerXmlReaderThe current reader position
contextXmlSerializationContextThe 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
sourceobjectThe object to be serialized
streamStreamThe stream for the resulting Xml-code
fragmentboolA 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
sourceobjectThe object to be serialized
writerTextWriterThe 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
sourceobjectThe object to be serialized
targetTextWriterThe TextWriter to write the Xml-code on
fragmentboolA 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
objobjectThe object to be serialized
pathstringThe path for the resulting Xml-file
fragmentboolA 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
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
objobjectThe object to be serialized
writerXmlWriterThe XmlWriter to write the Xml-code on
propertyIPropertySerializationInfoThe property for which the object is serialized
writeInstanceboolA value that indicates whether the serializer should write the element definition
identificationModeXmlIdentificationModeA value indicating whether it is allowed to the serializer to use identifier
contextXmlSerializationContextThe 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
sourceobjectThe object to be serialized
targetXmlWriterThe XmlWriter to write the Xml-code on
fragmentboolA 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
writerXmlWriterThe xml writer to write to
objobjectThe element
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe 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
writerXmlWriterThe xml writer to write to
objobjectThe element
valueobjectThe value of the attribute
propertyIPropertySerializationInfoThe property serialization information
contextXmlSerializationContextThe serialization context
WriteBeginElement(XmlWriter, object, ITypeSerializationInfo)
Writes the beginning of an element
protected virtual void WriteBeginElement(XmlWriter writer, object obj, ITypeSerializationInfo info)
Parameters
writerXmlWriterThe xml writer to write to
objobjectThe element
infoITypeSerializationInfoThe 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
writerXmlWriterThe xml writer to write to
rootobjectThe root element
infoITypeSerializationInfoThe 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
writerXmlWriterThe xml writer to write to
objobjectThe element
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe 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
writerXmlWriterThe xml writer to write to
objobjectThe element
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe 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
writerXmlWriterThe xml writer to write to
objobjectThe element
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe 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
writerXmlWriterThe xml writer to write to
objobjectThe element
infoITypeSerializationInfoThe 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
writerXmlWriterThe xml writer to write to
rootobjectThe element
infoITypeSerializationInfoThe 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
writerXmlWriterThe xml writer to write to
objobjectThe element
identificationModeXmlIdentificationModeThe identification mode for the current object
infoITypeSerializationInfoThe serialization information of the objects type
contextXmlSerializationContextThe serialization context
Returns
- bool
true, if the object could be written as identified object, otherwise false