#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion 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. [StorableType("40C4AFC4-D6E9-43CB-9450-5ABC967DD83C")] 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(); } } }