Version 1 (modified by epitzer, 15 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 start 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 and is conveyed in type information tokens.