C# Class YAXLib.YAXSerializer

An XML serialization class which lets developers design the XML file structure and select the exception handling policy. This class also supports serializing most of the collection classes such as the Dictionary generic class.
Mostrar archivo Open project: sinairv/YAXLib Class Usage Examples

Private Properties

Property Type Description
AddNamespacesToElement void
AddObjectToElement System.Xml.Linq.XElement
AtLeastOneOfCollectionMembersExists bool
AtLeastOneOfMembersExists bool
CreateElementWithNamespace System.Xml.Linq.XElement
DeserializeBase object
DeserializeCollectionMember void
DeserializeCollectionValue object
DeserializeKeyValuePair object
DeserializeTaggedDictionaryMember void
DeserializeTaggedDictionaryValue object
FinalizeNewSerializer void
FindDocumentDefaultNamespace void
GetArrayDimentionalIndex int[]
GetFieldsToBeSerialized IEnumerable
GetFieldsToBeSerialized IEnumerable
ImportNamespaces void
InvokeCustomDeserializerFromAttribute object
InvokeCustomDeserializerFromElement object
InvokeCustomDeserializerFromValue object
InvokeCustomSerializerToAttribute void
InvokeCustomSerializerToElement void
InvokeCustomSerializerToValue string
MakeBaseElement XElement
MakeCollectionElement XElement
MakeDictionaryElement XElement
MakeElement XElement
NewInternalSerializer YAXSerializer
OnExceptionOccurred void
PushObjectToSerializationStack void
RegisterNamespace void
RegisterYaxLibNamespace void
RetreiveElementValue void
SerializeBase XElement
SerializeBase XElement
SerializeXDocument XDocument
SetBaseElement void
SetNamespaceToOverrideEmptyNamespace void
VerifyDictionaryPairElements bool

Public Methods

Method Description
CleanUpAuxiliaryMemory ( ) : void

Cleans up auxiliary memory used by YAXLib during different sessions of serialization.

Deserialize ( TextReader textReader ) : object

Deserializes an object while reading input from an instance of TextReader.

Deserialize ( System.Xml.Linq.XElement element ) : object

Deserializes an object while reading from an instance of XElement

Deserialize ( XmlReader xmlReader ) : object

Deserializes an object while reading input from an instance of XmlReader.

Deserialize ( string input ) : object

Deserializes the specified string containing the XML serialization and returns an object.

DeserializeFromFile ( string fileName ) : object

Deserializes an object from the specified file which contains the XML serialization of the object.

Serialize ( object obj ) : string

Serializes the specified object and returns a string containing the XML.

Serialize ( object obj, TextWriter textWriter ) : void

Serializes the specified object into a TextWriter instance.

Serialize ( object obj, XmlWriter xmlWriter ) : void

Serializes the specified object into a XmlWriter instance.

SerializeToFile ( object obj, string fileName ) : void

Serializes the specified object to file.

SerializeToXDocument ( object obj ) : XDocument

Serializes the specified object and returns an instance of XDocument containing the result.

SetDeserializationBaseObject ( object obj ) : void

Sets the object used as the base object in the next stage of deserialization. This method enables multi-stage deserialization for YAXLib.

YAXSerializer ( Type type ) : System

Initializes a new instance of the YAXSerializer class.

YAXSerializer ( Type type, YAXExceptionHandlingPolicies exceptionPolicy ) : System

Initializes a new instance of the YAXSerializer class.

YAXSerializer ( Type type, YAXExceptionHandlingPolicies exceptionPolicy, YAXExceptionTypes defaultExType ) : System

Initializes a new instance of the YAXSerializer class.

YAXSerializer ( Type t, YAXExceptionHandlingPolicies exceptionPolicy, YAXExceptionTypes defaultExType, YAXSerializationOptions option ) : System

Initializes a new instance of the YAXSerializer class.

YAXSerializer ( Type type, YAXSerializationOptions seializationOptions ) : System

Initializes a new instance of the YAXSerializer class.

Private Methods

Method Description
AddNamespacesToElement ( System.Xml.Linq.XElement rootNode ) : void
AddObjectToElement ( System.Xml.Linq.XElement elem, System.Xml.Linq.XName alias, object obj ) : System.Xml.Linq.XElement

Adds an element contatining data related to the specified object, to an existing xml element.

AtLeastOneOfCollectionMembersExists ( System.Xml.Linq.XElement elem, MemberWrapper member ) : bool

Checks whether at least one of the collection memebers of the specified collection exists.

AtLeastOneOfMembersExists ( System.Xml.Linq.XElement elem, Type type ) : bool

Checks whether at least one of the memebers (property or field) of the specified object exists.

CreateElementWithNamespace ( UdtWrapper wrapper, System.Xml.Linq.XName className ) : System.Xml.Linq.XElement

Adds the namespace applying to the object type specified in wrapper to the className

DeserializeBase ( System.Xml.Linq.XElement baseElement ) : object

The basic method which performs the whole job of deserialization.

DeserializeCollectionMember ( object o, MemberWrapper member, Type colType, string elemValue, System.Xml.Linq.XElement xelemValue ) : void

Deserializes the collection member.

DeserializeCollectionValue ( Type colType, System.Xml.Linq.XElement xelemValue, System.Xml.Linq.XName memberAlias, YAXCollectionAttribute colAttrInstance ) : object

Retreives the collection value.

DeserializeKeyValuePair ( System.Xml.Linq.XElement baseElement ) : object

Deserializes the XML reperesentation of a key-value pair, as specified, and returns a KeyValuePair instance containing the deserialized data.

DeserializeTaggedDictionaryMember ( object o, MemberWrapper member, System.Xml.Linq.XElement xelemValue ) : void

Deserializes a dictionary member which also benefits from a YAXDictionary attribute

DeserializeTaggedDictionaryValue ( System.Xml.Linq.XElement xelemValue, System.Xml.Linq.XName alias, Type type, YAXCollectionAttribute colAttributeInstance, YAXDictionaryAttribute dicAttrInstance ) : object
FinalizeNewSerializer ( YAXSerializer serializer, bool importNamespaces, bool popFromSerializationStack = true ) : void
FindDocumentDefaultNamespace ( ) : void
GetArrayDimentionalIndex ( long linInd, int dims ) : int[]

Gets the dimensional index for an element of a multi-dimensional array from a linear index specified.

GetFieldsToBeSerialized ( ) : IEnumerable

Gets the sequence of fields to be serialized for the serializer's underlying type. This sequence is retreived according to the field-types specified by the user.

GetFieldsToBeSerialized ( UdtWrapper typeWrapper ) : IEnumerable

Gets the sequence of fields to be serialized for the specified type. This sequence is retreived according to the field-types specified by the user.

ImportNamespaces ( YAXSerializer otherSerializer ) : void
InvokeCustomDeserializerFromAttribute ( Type customDeserType, XAttribute attrToDeser ) : object
InvokeCustomDeserializerFromElement ( Type customDeserType, XElement elemToDeser ) : object
InvokeCustomDeserializerFromValue ( Type customDeserType, string valueToDeser ) : object
InvokeCustomSerializerToAttribute ( Type customSerType, object objToSerialize, XAttribute attrToFill ) : void
InvokeCustomSerializerToElement ( Type customSerType, object objToSerialize, XElement elemToFill ) : void
InvokeCustomSerializerToValue ( Type customSerType, object objToSerialize ) : string
MakeBaseElement ( XElement insertionLocation, XName name, object value, bool &alreadyAdded ) : XElement

Makes an XML element with the specified name, corresponding to the object specified.

MakeCollectionElement ( XElement insertionLocation, XName elementName, object elementValue, YAXCollectionAttribute collectionAttrInst, string format ) : XElement

Serializes a collection object.

MakeDictionaryElement ( XElement insertionLocation, XName elementName, object elementValue, YAXDictionaryAttribute dicAttrInst, YAXCollectionAttribute collectionAttrInst ) : XElement

Creates a dictionary element according to the specified options, as described by the attribute instances.

MakeElement ( XElement insertionLocation, MemberWrapper member, object elementValue, bool &moveDescOnly, bool &alreadyAdded ) : XElement

Makes the element corresponding to the member specified.

NewInternalSerializer ( Type type, XNamespace namespaceToOverride, XElement insertionLocation ) : YAXSerializer
OnExceptionOccurred ( YAXException ex, YAXExceptionTypes exceptionType ) : void

Called when an exception occurs inside the library. It applies the exception handling policies.

PushObjectToSerializationStack ( object obj ) : void
RegisterNamespace ( XNamespace ns, string prefix ) : void

Registers the namespace to be added to the root element of the serialized document.

RegisterYaxLibNamespace ( ) : void
RetreiveElementValue ( object o, MemberWrapper member, string elemValue, XElement xelemValue ) : void

Retreives the value of the element from the specified XML element or attribute.

SerializeBase ( object obj ) : XElement

One of the base methods that perform the whole job of serialization.

SerializeBase ( object obj, XName className ) : XElement

The base method that performs the whole job of serialization. Other serialization methods call this method to have their job done.

SerializeXDocument ( object obj ) : XDocument

Serializes the object into an XDocument object.

SetBaseElement ( XElement baseElement ) : void

Sets the base XML element. This method is used when an XMLSerializer instantiates another XMLSerializer to serialize nested objects. Through this method the child objects have access to the already serialized elements of their parent.

SetNamespaceToOverrideEmptyNamespace ( XNamespace otherNamespace ) : void
VerifyDictionaryPairElements ( Type &keyType, bool &isKeyAttrib, bool &isKeyContent, XName keyAlias, XElement childElem ) : bool

Verifies the existence of dictionary pair Key and Value elements.

Method Details

CleanUpAuxiliaryMemory() public static method

Cleans up auxiliary memory used by YAXLib during different sessions of serialization.
public static CleanUpAuxiliaryMemory ( ) : void
return void

Deserialize() public method

Deserializes an object while reading input from an instance of TextReader.
public Deserialize ( TextReader textReader ) : object
textReader TextReader The TextReader instance to read input from.
return object

Deserialize() public method

Deserializes an object while reading from an instance of XElement
public Deserialize ( System.Xml.Linq.XElement element ) : object
element System.Xml.Linq.XElement The XElement instance to read from.
return object

Deserialize() public method

Deserializes an object while reading input from an instance of XmlReader.
public Deserialize ( XmlReader xmlReader ) : object
xmlReader XmlReader The XmlReader instance to read input from.
return object

Deserialize() public method

Deserializes the specified string containing the XML serialization and returns an object.
public Deserialize ( string input ) : object
input string The input string containing the XML serialization.
return object

DeserializeFromFile() public method

Deserializes an object from the specified file which contains the XML serialization of the object.
public DeserializeFromFile ( string fileName ) : object
fileName string Path to the file.
return object

Serialize() public method

Serializes the specified object and returns a string containing the XML.
public Serialize ( object obj ) : string
obj object The object to serialize.
return string

Serialize() public method

Serializes the specified object into a TextWriter instance.
public Serialize ( object obj, TextWriter textWriter ) : void
obj object The object to serialize.
textWriter TextWriter The TextWriter instance.
return void

Serialize() public method

Serializes the specified object into a XmlWriter instance.
public Serialize ( object obj, XmlWriter xmlWriter ) : void
obj object The object to serialize.
xmlWriter XmlWriter The XmlWriter instance.
return void

SerializeToFile() public method

Serializes the specified object to file.
public SerializeToFile ( object obj, string fileName ) : void
obj object The object to serialize.
fileName string Path to the file.
return void

SerializeToXDocument() public method

Serializes the specified object and returns an instance of XDocument containing the result.
public SerializeToXDocument ( object obj ) : XDocument
obj object The object to serialize.
return XDocument

SetDeserializationBaseObject() public method

Sets the object used as the base object in the next stage of deserialization. This method enables multi-stage deserialization for YAXLib.
public SetDeserializationBaseObject ( object obj ) : void
obj object The object used as the base object in the next stage of deserialization.
return void

YAXSerializer() public method

Initializes a new instance of the YAXSerializer class.
public YAXSerializer ( Type type ) : System
type Type The type of the object being serialized/deserialized.
return System

YAXSerializer() public method

Initializes a new instance of the YAXSerializer class.
public YAXSerializer ( Type type, YAXExceptionHandlingPolicies exceptionPolicy ) : System
type Type The type of the object being serialized/deserialized.
exceptionPolicy YAXExceptionHandlingPolicies The exception handling policy.
return System

YAXSerializer() public method

Initializes a new instance of the YAXSerializer class.
public YAXSerializer ( Type type, YAXExceptionHandlingPolicies exceptionPolicy, YAXExceptionTypes defaultExType ) : System
type Type The type of the object being serialized/deserialized.
exceptionPolicy YAXExceptionHandlingPolicies The exception handling policy.
defaultExType YAXExceptionTypes The exceptions are treated as the value specified, unless otherwise specified.
return System

YAXSerializer() public method

Initializes a new instance of the YAXSerializer class.
public YAXSerializer ( Type t, YAXExceptionHandlingPolicies exceptionPolicy, YAXExceptionTypes defaultExType, YAXSerializationOptions option ) : System
t Type The type of the object being serialized/deserialized.
exceptionPolicy YAXExceptionHandlingPolicies The exception handling policy.
defaultExType YAXExceptionTypes The exceptions are treated as the value specified, unless otherwise specified.
option YAXSerializationOptions The serialization option.
return System

YAXSerializer() public method

Initializes a new instance of the YAXSerializer class.
public YAXSerializer ( Type type, YAXSerializationOptions seializationOptions ) : System
type Type The type of the object being serialized/deserialized.
seializationOptions YAXSerializationOptions The serialization option flags.
return System