Tools for serialization-deserialization

Library ICSSoft.STORMNET.Tools.dll provides various tools to work in her classes implemented functions:

  • serialization-deserialization
  • XML,
  • send mail
  • file compression
  • processing of signed assemblies
  • , etc.

Data helper methods recommended for application developers.

Tools for serialization-deserialization

When choosing between binary and SOAP serialization should be aware that binary form serialization more productive and result strings get shorter.

ICSSoft.STORMNET.Tools.ToolXML

ICSSoft.STORMNET.Tools.ToolXML tool for serialization-deserialization in XML.

This class implements two versions of the transformation in XML:

  • SOAP serialization using a standard System.Runtime.Serialization.Formatters.Soap.SoapFormatter,
  • implemented conversion data object to XmlDocument applicable only for ICSSoft.STORMNET.DataObject (this variant is available in the article).

The class implements the following methods:

XMLDocument2DataObject

Appointment_: Receiving a data object from previously received XML document. This method is written specifically for ICSSoft.STORMNET.DataObject

Settings:

  • dataObject - the data Object to deserialize
  • xmlDoc - Serialized object data
public static void XMLDocument2DataObject(ref ICSSoft.STORMNET.DataObject dataObject, XmlDocument xmlDoc)

DataObject2XMLDocument

Appointment_: Receiving an XML document from a data object. This type of serialization is written specifically for ICSSoft.STORMNET.DataObject and is based on iterating properties, datalow and references to masters, followed by the entry of all this XMLDocument.

Settings:

  • dataObject - the object data
  • serializeAggregators - to serialize detaily
  • setObjectLoadingStateLoaded - Set LoadingState object in Loaded
  • setObjectStatusCreated - Set the ObjectStatus object Created in
  • serializeMasters - to do a complete serialization of the masters of objects

The result is: a Serialized representation of the object

// 1. 
public static XmlDocument DataObject2XMLDocument(ref ICSSoft.STORMNET.DataObject dataObject)

// 2. 
public static XmlDocument DataObject2XMLDocument(ref ICSSoft.STORMNET.DataObject dataObject, bool serializeAggregators)

// 3. 
public static XmlDocument DataObject2XMLDocument(ref ICSSoft.STORMNET.DataObject dataObject, bool serializeAggregators, bool setObjectLoadingStateLoaded, bool setObjectStatusCreated)

// 4. 
public static XmlDocument DataObject2XMLDocument(
            ref ICSSoft.STORMNET.DataObject dataObject, 
            bool serializeAggregators,
            bool setObjectLoadingStateLoaded, 
            bool setObjectStatusCreated, 
            bool serializeMasters)

ObjectToString

Assign: the serialization of the object using SoapFormatter.

Settings:

o - the Object to serialize

The result is: a Serialized object

public static string ObjectToString(object o)

ObjectFromString

Assign: deserialize the object using the SoapFormatter.

Settings:

s - Serialized object

The result is: Restored object

public static object ObjectFromString(string s)

ICSSoft.STORMNET.Tools.ToolBinarySerializer

ICSSoft.STORMNET.Tools.ToolBinarySerializer tool for binary serialization-deserialization.

Serialized bytes are converted to ToBase64String. The implementation is based on примененииSystem.Runtime.Serialization.Formatters.Binary.BinaryFormatter.

The class implements the following methods:

ObjectToString

Assign: the serialization of the object using BinaryFormatter.

Settings:

o Object

The result is: String.

public static string ObjectToString(object o)

ObjectFromString

Assign: deserialize the object using the BinaryFormatter.

Settings:

  • s - Serialized object
  • binder - Binder, which you must specify when deserialization need to implement your own logic for searching types.

The result is: the Restored object.

// 1. 
public static object ObjectFromString(string s)

// 2. 
public static object ObjectFromString(string s, SerializationBinder binder)

ICSSoft.STORMNET.Tools.XmlTools

ICSSoft.STORMNET.Tools.XmlTools class for working with XML.

The class implements the following methods:

GetXDocumentByXElement

Assign: Conversion System.Xml.Linq.XElement in System.Xml.XmlDocument.

Settings:

  • xElement - xElement to convert.
  • versionXmlDoc Version of the generated xml document.
  • encodingXmlDoc - Encoding for the generated xml document.

The result is: the Result of conversion - XmlDocument.

public static XmlDocument GetXDocumentByXElement(XElement xElement, string versionXmlDoc, string encodingXmlDoc)

LoadXml

Assign: Read an Xml file. Can automatically detect the encoding based on the encoding, used inside Xml.

Settings:

  • filePath - Path to the Xml file.
  • encoding - the character Encoding to use to read the Xml file.
public static XmlDocument LoadXml(string filePath, Encoding encoding = null)