| IGLib 1.7.2 The IGLib base library for development of numerical, technical and business applications.

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Classes | Public Member Functions | Static Public Member Functions | List of all members
IG.Lib.SerializerBase Class Referenceabstract

Base class for serialization helper classes. More...

Inheritance diagram for IG.Lib.SerializerBase:
[legend]
Collaboration diagram for IG.Lib.SerializerBase:
[legend]

## Classes
interface | ISerializationTestArrayMember
| Interface for members of arrays in classes for testing serialization. More...
interface | ISerializationTestClass
| Interface for classes for testing serialization. More...
class | SerializationTestArrayMember
| Member of arrays in test classes for testing serialization. More...
class | SerializationTestClass
| Test class for testing serialization. More...
class | TestClass
| Simple class using for testing serialization. More...
class | TestClassDerived
| Simple derived class using for testing serialization. More...

## Public Member Functions
| SerializerBase ()
abstract void | Serialize< T > (T serializedObject, Stream serializationStream)
| Serializes the specified object and outputs it to a stream. More...
void | Serialize< T > (T serializedObject, string filePath)
| Serializes the specified object and outputs it to a file. If the specified file exists then it is overwritten. More...
void | Serialize< T > (T serializedObject, string filePath, bool append)
| Serializes the specified object and outputs it to a file. More...
string | Serialize< T > (T obj)
| Serializes the specified object to a string and returns it. More...
abstract T | Deserialize< T > (Stream deserializationStream)
| Deserializes an object from the specified stream containing JSON representation of the object. Deserialized object is instantiated and returned. More...
T | DeserializeString< T > (string strSerialized)
| Deserializes an object from JSON - serialized string representation and returns it. More...
T | DeserializeFile< T > (string filePath)
| Deserializes an object from JSON - serialized file and returns it. More...

## Static Public Member Functions
static void | TestSerializationAll (string outputDirectory)
| Tests different serialization methods with different data. More...
static void | TestSerializationDto< TypeDto, Type > (ISerializer serializer, Type serializedObject, string filePath, bool firstStep, bool secondStep)
| Test serialization performed by the specified serialization helper class. This test does not perform only serialization/deserialization, but also performs copying of an object to and from the corresponding DTO (Data Transfer Object). It is actually DTO that is serialized and deserialized. This function creates a test object, copies it to the corresponding DTO (Data Transfer object) of the specified type, serializes it and stores it to a file, then deserializes the DTO (instantiates a new object for the stored record), copies the contents of the DTO to a new object, creates a new object and copies data to it from the DTO, and serializes the DTO again and writes it into another file in the same directory, but with a modified name. Both files can then be compared in order to see if something was lost during conversions or serialization/deserialization. More...
static void | TestSerializationDto< TypeDto, Type, BaseType > (ISerializer serializer, Type serializedObject, string filePath, bool firstStep, bool secondStep)
| Test serialization performed by the specified serialization helper class. This test does not perform only serialization/deserialization, but also performs copying of an object to and from the corresponding DTO (Data Transfer Object). It is actually the DTO that is serialized and deserialized. This function creates a test object, copies it to the corresponding DTO (Data Transfer object) of the specified type, serializes it and stores it to a file, then deserializes the DTO (instantiates a new object for the stored record), copies the contents of the DTO to a new object, creates a new object and copies data to it from the DTO, and serializes the DTO again and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost during conversions or serialization/deserialization. IMPORTANT REMARK: In most cases one will not need this function, but can use the variant with only two type parameters (BaseType omitted). More...
static void | TestSerialization< SerializationTestClass > (ISerializer serializer, SerializationTestClass serObject, string filePath)
| Test serialization performed by the specified serialization helper class. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost. More...
static void | TestSerialization< TypeSer > (ISerializer serializer, TypeSer serObject, string filePath, bool firstStep, bool secondStep)
| Test serialization performed by the specified serialization helper class. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost. More...
static void | TestSerializationJSON (string filePath, object serObject)
| Test serialization performed by the specified serialization helper class. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost. More...
static void | TestSerializationJSON (string filePath)
| Test serialization performed by the JSon serializer. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost. More...
static void | TestType< T > (T obj)
| Writes the type of the object passed as parameter in two ways: by using tpye parameter of the generic method and by using object's GetType() method. The object itself is not printed out. More...
static void | TestType< T > (T obj, bool printObject)
| Writes the type of the object passed as parameter in two ways: by using tpye parameter of the generic method and by using object's GetType() method. More...
static void | ExampleTestType ()
| Testing the type of the object within a generic method. More...

## Detailed Description

Base class for serialization helper classes.

$A Igor May09;

## Constructor & Destructor Documentation

IG.Lib.SerializerBase.SerializerBase | ( |  | ) |
| inline

## Member Function Documentation

abstract void IG.Lib.SerializerBase.Serialize< T > | ( | T | serializedObject,
|  | Stream | serializationStream
| ) |  |
| pure virtual

Serializes the specified object and outputs it to a stream.

Template Parameters

  T | Type of the object to be serialized.

Parameters

  serializedObject | Object to be serialized.
  serializationStream | Stream on which the serialized object is output.

Implements IG.Lib.ISerializer.

Implemented in IG.Lib.SerializerJsonBase, and IG.Lib.SerializerJson.

void IG.Lib.SerializerBase.Serialize< T > | ( | T | serializedObject,
|  | string | filePath
| ) |  |
| inline

Serializes the specified object and outputs it to a file. If the specified file exists then it is overwritten.

Template Parameters

  T | Type of the object to be serialized.

Parameters

  serializedObject | Object to be serialized.
  filePath | Path to the file that serialized object is written to.

Implements IG.Lib.ISerializer.

void IG.Lib.SerializerBase.Serialize< T > | ( | T | serializedObject,
|  | string | filePath,
|  | bool | append
| ) |  |
| inline

Serializes the specified object and outputs it to a file.

Template Parameters

  T | Type of the object to be serialized.

Parameters

  serializedObject | Object to be serialized.
  filePath | Path to the file that serialized object is written to.
  append | If true then the generated contents is appended to a file.

Implements IG.Lib.ISerializer.

string IG.Lib.SerializerBase.Serialize< T > | ( | T | obj | ) |
| inline

Serializes the specified object to a string and returns it.

Template Parameters

  T | Type of the object to be serialized.

Parameters

  obj | Objejct to be serialized.

Returns
  String containing the serialized object.

Implements IG.Lib.ISerializer.

abstract T IG.Lib.SerializerBase.Deserialize< T > | ( | Stream | deserializationStream | ) |
| pure virtual

Deserializes an object from the specified stream containing JSON representation of the object. Deserialized object is instantiated and returned.

Template Parameters

  T | Type of the deserialized object.

Parameters

  deserializationStream | Stream from which object is deserialized.

Returns
  Object that is deserialized from the stream.

Implements IG.Lib.ISerializer.

Implemented in IG.Lib.SerializerJsonBase.

T IG.Lib.SerializerBase.DeserializeString< T > | ( | string | strSerialized | ) |
| inline

Deserializes an object from JSON - serialized string representation and returns it.

Template Parameters

  T | Type of the deserialized object.

Parameters

  strSerialized | String containing the serialized object.

Returns
  Object instantiated form the serialiyed representation.

Implements IG.Lib.ISerializer.

T IG.Lib.SerializerBase.DeserializeFile< T > | ( | string | filePath | ) |
| inline

Deserializes an object from JSON - serialized file and returns it.

Template Parameters

  T | Type of the deserialized object.

Parameters

  filePath | Path to thefile. File must contain the appropriately serialized object of the correct type.

Returns
  Object deserialized from the file.

Implements IG.Lib.ISerializer.

static void IG.Lib.SerializerBase.TestSerializationAll | ( | string | outputDirectory | ) |
| inline static

Tests different serialization methods with different data.

Parameters

  outputDirectory | Directory where test files are kept.

References IG.Num.AnalysisResults.CreateExample(), and IG.Lib.SerializerBase.SerializationTestClass.CreateTestObject().

static void IG.Lib.SerializerBase.TestSerializationDto< TypeDto, Type > | ( | ISerializer | serializer,
|  | Type | serializedObject,
|  | string | filePath,
|  | bool | firstStep,
|  | bool | secondStep
| ) |  |
| inline static

Test serialization performed by the specified serialization helper class. This test does not perform only serialization/deserialization, but also performs copying of an object to and from the corresponding DTO (Data Transfer Object). It is actually DTO that is serialized and deserialized. This function creates a test object, copies it to the corresponding DTO (Data Transfer object) of the specified type, serializes it and stores it to a file, then deserializes the DTO (instantiates a new object for the stored record), copies the contents of the DTO to a new object, creates a new object and copies data to it from the DTO, and serializes the DTO again and writes it into another file in the same directory, but with a modified name. Both files can then be compared in order to see if something was lost during conversions or serialization/deserialization.

Template Parameters

  TypeDto | Declared type of the DTO to that is used for storing and serializing object contents (state). The type must implements implement a default constructor.
  Type | Type of the object to be serialized/deserialized through corresponding DTO.

Parameters

  serializer | Serialization helper object that is used for serialization.
  serializedObject | Object to be serialized.
  filePath | Name of the file to which serialized object si written. Another file is created in the same directory for storing deserialized/serialized object.
  firstStep | If false then the first step is not performed (serialization to a file). This is useful if we already have a file with serialized object, and we would like to change it ans observe how changes are reflected in the second file where deserialized/serialized object is stored.
  secondStep | If false then the second step is not (deserialization/serialization) performed.

Type Constraints

  Type | : | class |
  TypeDto | : | SerializationDto<Type> |
  TypeDto | : | new() |

static void IG.Lib.SerializerBase.TestSerializationDto< TypeDto, Type, BaseType > | ( | ISerializer | serializer,
|  | Type | serializedObject,
|  | string | filePath,
|  | bool | firstStep,
|  | bool | secondStep
| ) |  |
| inline static

Test serialization performed by the specified serialization helper class. This test does not perform only serialization/deserialization, but also performs copying of an object to and from the corresponding DTO (Data Transfer Object). It is actually the DTO that is serialized and deserialized. This function creates a test object, copies it to the corresponding DTO (Data Transfer object) of the specified type, serializes it and stores it to a file, then deserializes the DTO (instantiates a new object for the stored record), copies the contents of the DTO to a new object, creates a new object and copies data to it from the DTO, and serializes the DTO again and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost during conversions or serialization/deserialization. IMPORTANT REMARK: In most cases one will not need this function, but can use the variant with only two type parameters (BaseType omitted).

Template Parameters

  TypeDto | Type of the DTO to that is used for storing and serializing object contents (state). The type must implements implement a default constructor.
  Type | Type of the object to be serialized/deserialized through corresponding DTO.
  BaseType | Base type from which Type inherits. It can be the same as Type. Serializer is initialized throug Type and VaseType.

Parameters

  serializer | Serialization helper object that is used for serialization.
  serializedObject | Object to be serialized.
  filePath | Name of the file to which serialized object is written. Another file is created in the same directory for storing deserialized/serialized object.

<paparam name="firstStep">If false then the first step is not performed (serialization to a file). This is useful if we already have a file with serialized object, and we would like to change it ans observe how changes are reflected in the second file where deserialized/serialized object is stored.</paparam>

Parameters

  firstStep | If false then the second step is not (deserialization/serialization) performed.
  secondStep | If false then the second step is not (deserialization/serialization) performed.

Type Constraints

  BaseType | : | class |
  Type | : | class |
  Type | : | BaseType |
  TypeDto | : | SerializationDtoBase |
  TypeDto | : | Type |
  TypeDto | : | BaseType |
  TypeDto | : | new() |

static void IG.Lib.SerializerBase.TestSerialization< SerializationTestClass > | ( | ISerializer | serializer,
|  | SerializationTestClass | serObject,
|  | string | filePath
| ) |  |
| inline static

Test serialization performed by the specified serialization helper class. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost.

Template Parameters

  SerializationTestClass | Declared type of the object to be serialized.

Parameters

  serializer | Serialization helper object that is used for serialization.
  serObject | Object to be serialized.
  filePath | Name of the file to which serialized object si written. Another file is created in the same directory for storing deserialized/serialized object.

static void IG.Lib.SerializerBase.TestSerialization< TypeSer > | ( | ISerializer | serializer,
|  | TypeSer | serObject,
|  | string | filePath,
|  | bool | firstStep,
|  | bool | secondStep
| ) |  |
| inline static

Test serialization performed by the specified serialization helper class. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost.

Template Parameters

  TypeSer | Declared type of the object to be serialized. Usually, TypeSer will be a type that implements ISerializer.

Parameters

  serializer | Serialization helper object that is used for serialization.
  serObject | Object to be serialized.
  filePath | Name of the file to which serialized object si written. Another file is created in the same directory for storing deserialized/serialized object.

<paparam name="firstStep">If false then the first step is not performed (serialization to a file). This is useful if we already have a file with serialized object, and we would like to change it ans observe how changes are reflected in the second file where deserialized/serialized object is stored.</paparam>

Parameters

  firstStep | If false then the second step is not (deserialization/serialization) performed.
  secondStep | If false then the second step is not (deserialization/serialization) performed.

static void IG.Lib.SerializerBase.TestSerializationJSON | ( | string | filePath,
|  | object | serObject
| ) |  |
| inline static

Test serialization performed by the specified serialization helper class. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost.

Parameters

  filePath | Name of the file to which serialized object si written. Another file is created in the same directory for storing deserialized/serialized object.
  serObject | >Object to be serialized.

static void IG.Lib.SerializerBase.TestSerializationJSON | ( | string | filePath | ) |
| inline static

Test serialization performed by the JSon serializer. This function creates a test object, serializes it ans stores it to a file, then deserializes it (instantiates a new object for the stored record), and serializes that object and writes it into another file in the same directory, with a modified name. Both files can then be compared in order to see if something was lost.

Parameters

  filePath | Path of te basic file used for saving a serialized object.

References IG.Lib.SerializerBase.SerializationTestClass.CreateTestObject().

static void IG.Lib.SerializerBase.TestType< T > | ( | T | obj | ) |
| inline static

Writes the type of the object passed as parameter in two ways: by using tpye parameter of the generic method and by using object's GetType() method. The object itself is not printed out.

Template Parameters

  T | Specified type of the object (as type parameter of the method).

Parameters

  obj | Object whose type printed.

static void IG.Lib.SerializerBase.TestType< T > | ( | T | obj,
|  | bool | printObject
| ) |  |
| inline static

Writes the type of the object passed as parameter in two ways: by using tpye parameter of the generic method and by using object's GetType() method.

Template Parameters

  T | Specified type of the object (as type parameter of the method).

Parameters

  obj | Object whose type printed.
  printObject | If true then the object itself is also printed out.

static void IG.Lib.SerializerBase.ExampleTestType | ( |  | ) |
| inline static

Testing the type of the object within a generic method.

The documentation for this class was generated from the following file:

- igbase/data/serialization/SerializerBase.cs