Free cookie consent management tool by TermsFeed Policy Generator
wiki:Documentation/DevelopmentCenter/UsePersistence

Version 3 (modified by swagner, 14 years ago) (diff)

--

HeuristicLab Persistence Quick Start Guide

Invocation

Use the classes XmlGenerator and XmlParser to transform an object graph into XML and read it back again. You can serialize into a file that is essentially a ZIP file with two entries or directly to a stream.

Custom Classes

  • Add the [StorableClass] attribute to your class
  • Add the [Storable] attribute to any fields or properties you would like to be persisted
  • Choose a constructor that is available to the persistence:
    • Either a default constructor with no arguments (can be private)
    • Or a [StorableConstructor] with a single bool argument (e.g. isDeserializing) that is set to true when invoked by the persistence

If you need more logic you can add a [PersistenceHook] attribute to parameterless methods that will be called before serialization starts or after serialization finishes for an object.

Support for Other Classes

  • An IPrimitiveSerializer directly transforms an object and its components into serialized form. This is mainly used for primitive types such as int or float.
  • An ICompositeSerializer does not directly transform an object into serialized form but decomposes it into other objects that can then be used to recompose the same object.

Other Formats

You can use the core persistence components to generate other formats. This is done through a stream of serialization tokens. The Serializer and Deserializer use classes of type ISerializationToken to talk to the back end. They describes a hierarchical format of composites that can contain other composites, primitives or references. Additionally, type information is conveyed in type information tokens.