Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Persistence/3.3/Core/PrimitiveSerializerBase.cs @ 11233

Last change on this file since 11233 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Text;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25
26namespace HeuristicLab.Persistence.Interfaces {
27
28  /// <summary>
29  /// Base class for primitive serializers. These are serializers that map
30  /// directly to a single datatype and directly produce a serializable object.
31  /// </summary>
32  /// <typeparam name="Source">The source type.</typeparam>
33  /// <typeparam name="SerialData">The serialized type.</typeparam>
34  [StorableClass]
35  public abstract class PrimitiveSerializerBase<Source, SerialData> :
36      IPrimitiveSerializer<Source, SerialData>
37      where SerialData : ISerialData {
38
39    /// <summary>
40    /// Formats the specified object.
41    /// </summary>
42    /// <param name="o">The object.</param>
43    /// <returns>A serialized version of the object.</returns>
44    public abstract SerialData Format(Source o);
45
46    /// <summary>
47    /// Parses the specified serialized data back into an object.
48    /// </summary>
49    /// <param name="data">The serial data.</param>
50    /// <returns>
51    /// A newly created object representing the serialized data.
52    /// </returns>
53    public abstract Source Parse(SerialData data);
54
55    /// <summary>
56    /// Gets the type of the serial data.
57    /// </summary>
58    /// <value>The type of the serial data.</value>
59    public Type SerialDataType { get { return typeof(SerialData); } }
60
61    /// <summary>
62    /// Gets the type of the source.
63    /// </summary>
64    /// <value>The type of the source.</value>
65    public Type SourceType { get { return typeof(Source); } }
66
67    /// <summary>
68    /// Formats the specified object.
69    /// </summary>
70    /// <param name="o">The object.</param>
71    /// <returns>A serialized version of the object.</returns>
72    ISerialData IPrimitiveSerializer.Format(object o) {
73      return Format((Source)o);
74    }
75
76    /// <summary>
77    /// Parses the specified serialized data back into an object.
78    /// </summary>
79    /// <param name="data">The serial data.</param>
80    /// <returns>A newly created object representing the serialized data.</returns>
81    object IPrimitiveSerializer.Parse(ISerialData data) {
82      return Parse((SerialData)data);
83    }
84
85    /// <summary>
86    /// Returns a <see cref="System.String"/> that represents this instance.
87    /// </summary>
88    /// <returns>
89    /// A <see cref="System.String"/> that represents this instance.
90    /// </returns>
91    public override string ToString() {
92      return new StringBuilder()
93        .Append(this.GetType().Name)
94        .Append('(')
95        .Append(SourceType.Name)
96        .Append("->")
97        .Append(SerialDataType.Name)
98        .ToString();
99    }
100
101  }
102
103}
Note: See TracBrowser for help on using the repository browser.