XmlSerializerBase<TObj, TXmlObj> Class
Provides the base class for an object that can serialize and deserialize a hierarchy of XmlObjectBase objects.
public abstract class XmlSerializerBase<TObj, TXmlObj> where TXmlObj : XmlObjectBase
- Type Parameters:
-
TObj-The Type of object that is represented by
TXmlObj.TXmlObj-The Type of XmlObjectBase to serialize/deserialize.
- Inheritance:
- object object
- Derived:
- DockSiteLayoutSerializer
Constructors
XmlSerializerBase(TXmlObj?)
Initializes an instance of the class.
protected XmlSerializerBase(TXmlObj? rootNode = null)
| Parameter | Type | Description |
|---|---|---|
| rootNode | TXmlObj | The root |
Properties
RootNode
The root TXmlObj node that is serialized and deserialized.
public TXmlObj? RootNode { get; set; }
Property Value
- TXmlObj
UseXmlSerializer
Indicates if System.Xml.Serialization.XmlSerializer is used when serializing and deserializing objects.
Methods
ApplyTo(TObj)
Applies the information contained within this serializer to the specified object.
public abstract void ApplyTo(TObj obj)
| Parameter | Type | Description |
|---|---|---|
| obj | TObj | The object to update with deserialized information. |
CreateRootNodeFor(TObj)
Creates a root node for the specified object.
public abstract TXmlObj CreateRootNodeFor(TObj obj)
| Parameter | Type | Description |
|---|---|---|
| obj | TObj | The object for which to create a root node. |
Returns
- TXmlObj:
The root node that was created.
EnableXmlSerializer()
Call this method to enable the use of System.Xml.Serialization.XmlSerializer when serializing and deserializing objects.
public void EnableXmlSerializer()
Remarks
The reflection-based System.Xml.Serialization.XmlSerializer may not be compatible with applications that support trimming of unused code.
GetXmlSerializer(IEnumerable<Type>)
Returns the System.Xml.Serialization.XmlSerializer to use for serialization and deserialization.
protected virtual XmlSerializer GetXmlSerializer(IEnumerable<Type> registeredTypes)
| Parameter | Type | Description |
|---|---|---|
| registeredTypes | IEnumerable<Type> | The registered types to be supported by the serializer. |
Returns
- XmlSerializer
LoadFromFile(string)
Deserializes the RootNode from the specified file.
public void LoadFromFile(string path)
| Parameter | Type | Description |
|---|---|---|
| path | string | The path to the file from which to read an object. |
LoadFromFile(string, TObj)
Deserializes the RootNode from the specified file.
public void LoadFromFile(string path, TObj obj)
| Parameter | Type | Description |
|---|---|---|
| path | string | The path to the file from which to read an object. |
| obj | TObj | The object to update with data. |
LoadFromStream(Stream)
public void LoadFromStream(Stream stream)
| Parameter | Type | Description |
|---|---|---|
| stream | Stream | The Stream from which to read an object. |
LoadFromStream(Stream, TObj)
public void LoadFromStream(Stream stream, TObj obj)
| Parameter | Type | Description |
|---|---|---|
| stream | Stream | The Stream from which to read an object. |
| obj | TObj | The object to update with data. |
LoadFromString(string)
Deserializes the RootNode from the specified XML string.
public void LoadFromString(string xml)
| Parameter | Type | Description |
|---|---|---|
| xml | string | The XML string from which to read an object. |
LoadFromString(string, TObj)
Deserializes the RootNode from the specified XML string.
public void LoadFromString(string xml, TObj obj)
| Parameter | Type | Description |
|---|---|---|
| xml | string | The XML string from which to read an object. |
| obj | TObj | The object to update with data. |
LoadFromXmlReader(XmlReader)
Deserializes the RootNode from the specified System.Xml.XmlReader.
public void LoadFromXmlReader(XmlReader reader)
| Parameter | Type | Description |
|---|---|---|
| reader | XmlReader | The System.Xml.XmlReader from which to read an object. |
LoadFromXmlReader(XmlReader, TObj)
Deserializes the RootNode from the specified System.Xml.XmlReader.
public void LoadFromXmlReader(XmlReader reader, TObj obj)
| Parameter | Type | Description |
|---|---|---|
| reader | XmlReader | The System.Xml.XmlReader from which to read an object. |
| obj | TObj | The object to update with data. |
OnObjectDeserialized(ItemSerializationEventArgs)
Invoked just before the ObjectDeserialized event.
protected virtual void OnObjectDeserialized(ItemSerializationEventArgs eventArgs)
| Parameter | Type | Description |
|---|---|---|
| eventArgs | ItemSerializationEventArgs | The ItemSerializationEventArgs instance containing the event data. |
OnObjectSerialized(ItemSerializationEventArgs)
Invoked just before the ObjectSerialized event.
protected virtual void OnObjectSerialized(ItemSerializationEventArgs eventArgs)
| Parameter | Type | Description |
|---|---|---|
| eventArgs | ItemSerializationEventArgs | The ItemSerializationEventArgs instance containing the event data. |
QuerySerializerProperties(object)
Returns the metadata for an object's serializable properties.
protected virtual IEnumerable<IXmlSerializerProperty> QuerySerializerProperties(object source)
| Parameter | Type | Description |
|---|---|---|
| source | object | The object to examine. |
Returns
RaiseObjectDeserialized(ItemSerializationEventArgs)
Raises the ObjectDeserialized event with the specified arguments.
protected void RaiseObjectDeserialized(ItemSerializationEventArgs eventArgs)
| Parameter | Type | Description |
|---|---|---|
| eventArgs | ItemSerializationEventArgs | The ItemSerializationEventArgs instance containing the event data. |
RaiseObjectSerialized(ItemSerializationEventArgs)
Raises the ObjectSerialized event with the specified arguments.
protected void RaiseObjectSerialized(ItemSerializationEventArgs eventArgs)
| Parameter | Type | Description |
|---|---|---|
| eventArgs | ItemSerializationEventArgs | The ItemSerializationEventArgs instance containing the event data. |
ReadRootNode(XmlReader)
Reads the root node of the XML document.
protected virtual TXmlObj? ReadRootNode(XmlReader reader)
| Parameter | Type | Description |
|---|---|---|
| reader | XmlReader | The System.Xml.XmlReader to read from. |
Returns
- TXmlObj
See Also
RegisterType(Type, IEnumerable<IXmlSerializerProperty>?)
Registers a Types that can be serialized and deserialized using this serializer.
public void RegisterType(Type type, IEnumerable<IXmlSerializerProperty>? properties = null)
| Parameter | Type | Description |
|---|---|---|
| type | Type | The Type to be registered. |
| properties | IEnumerable<IXmlSerializerProperty> | The properties to be serialized with the Type when not using System.Xml.Serialization.XmlSerializer. Types that derive from XmlObjectBase should override GetSerializerProperties() instead of passing properties to this method. |
Remarks
If the object graph contains any Type that is not registered with the serializer, an exception may occur during serialization and deserialization.
RegisterType<T>(IEnumerable<IXmlSerializerProperty>?)
Registers a Types that can be serialized and deserialized using this serializer.
public void RegisterType<T>(IEnumerable<IXmlSerializerProperty>? properties = null)
- Type Parameters:
-
T-The Type to be registered.
| Parameter | Type | Description |
|---|---|---|
| properties | IEnumerable<IXmlSerializerProperty> |
Remarks
If the object graph contains any Type that is not registered with the serializer, an exception may occur during serialization and deserialization.
ResolveType(string)
Resolves the Type associated with the given XML name for the type.
protected virtual Type? ResolveType(string xmlTypeName)
| Parameter | Type | Description |
|---|---|---|
| xmlTypeName | string | The XML name of a type. |
Returns
ResolveXmlTypeName(Type)
Resolves the XML name of a given type.
protected static string ResolveXmlTypeName(Type type)
| Parameter | Type | Description |
|---|---|---|
| type | Type | The type to examine. |
Returns
SaveToFile(string)
Serializes the RootNode to XML within a file.
public void SaveToFile(string path)
| Parameter | Type | Description |
|---|---|---|
| path | string | The path to the output file. |
SaveToFile(string, TObj)
Serializes the RootNode to XML within a file.
public void SaveToFile(string path, TObj obj)
| Parameter | Type | Description |
|---|---|---|
| path | string | The path to the output file. |
| obj | TObj | The object for which to serialize data. |
SaveToStream(Stream)
public void SaveToStream(Stream stream)
| Parameter | Type | Description |
|---|---|---|
| stream | Stream | The Stream to write to. |
SaveToStream(Stream, TObj)
public void SaveToStream(Stream stream, TObj obj)
| Parameter | Type | Description |
|---|---|---|
| stream | Stream | The Stream to write to. |
| obj | TObj | The object for which to serialize data. |
SaveToString()
Serializes the RootNode to an XML string.
SaveToString(TObj)
Serializes the RootNode to an XML string.
public string SaveToString(TObj obj)
| Parameter | Type | Description |
|---|---|---|
| obj | TObj | The object for which to serialize data. |
Returns
- string:
The XML string that was created.
SaveToXmlWriter(XmlWriter)
Serializes the RootNode to XML by using an System.Xml.XmlWriter.
public void SaveToXmlWriter(XmlWriter writer)
| Parameter | Type | Description |
|---|---|---|
| writer | XmlWriter | The System.Xml.XmlWriter to write to. |
SaveToXmlWriter(XmlWriter, TObj)
Serializes the RootNode to XML by using an System.Xml.XmlWriter.
public void SaveToXmlWriter(XmlWriter writer, TObj obj)
| Parameter | Type | Description |
|---|---|---|
| writer | XmlWriter | The System.Xml.XmlWriter to write to. |
| obj | TObj | The object for which to serialize data. |
WriteHeader(XmlWriter)
Allows for dynamic injection of an XML comment or other data before the main serialization routine occurs.
protected virtual void WriteHeader(XmlWriter writer)
| Parameter | Type | Description |
|---|---|---|
| writer | XmlWriter | The System.Xml.XmlWriter to write to. |
WriteRootNode(XmlWriter, TXmlObj)
Writes the root node of the XML document.
protected void WriteRootNode(XmlWriter writer, TXmlObj obj)
| Parameter | Type | Description |
|---|---|---|
| writer | XmlWriter | The System.Xml.XmlWriter to write to. |
| obj | TXmlObj | The serialized root node data. |
See Also
Events
ObjectDeserialized
Occurs when an object is deserialized.
public event EventHandler<ItemSerializationEventArgs>? ObjectDeserialized
Event Type
ObjectSerialized
Occurs when an object is serialized.
public event EventHandler<ItemSerializationEventArgs>? ObjectSerialized
Event Type
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()