using System; using System.Text; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Persistence.Interfaces { /// /// Base class for primitive serializers. These are serializers that map /// directly to a single datatype and directly produce a serializable object. /// /// The source type. /// The serialized type. [StorableClass] public abstract class PrimitiveSerializerBase : IPrimitiveSerializer where SerialData : ISerialData { /// /// Formats the specified object. /// /// The object. /// A serialized version of the object. public abstract SerialData Format(Source o); /// /// Parses the specified serialized data back into an object. /// /// The serial data. /// /// A newly created object representing the serialized data. /// public abstract Source Parse(SerialData data); /// /// Gets the type of the serial data. /// /// The type of the serial data. public Type SerialDataType { get { return typeof(SerialData); } } /// /// Gets the type of the source. /// /// The type of the source. public Type SourceType { get { return typeof(Source); } } /// /// Formats the specified object. /// /// The object. /// A serialized version of the object. ISerialData IPrimitiveSerializer.Format(object o) { return Format((Source)o); } /// /// Parses the specified serialized data back into an object. /// /// The serial data. /// A newly created object representing the serialized data. object IPrimitiveSerializer.Parse(ISerialData data) { return Parse((SerialData)data); } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { return new StringBuilder() .Append(this.GetType().Name) .Append('(') .Append(SourceType.Name) .Append("->") .Append(SerialDataType.Name) .ToString(); } } }