Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Persistence/3.3/Interfaces/ICompositeSerializer.cs @ 15626

Last change on this file since 15626 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.Collections.Generic;
24using HeuristicLab.Persistence.Core;
25
26namespace HeuristicLab.Persistence.Interfaces {
27
28  /// <summary>
29  /// A composite serializer does not directly transform an object into its
30  /// serialized form. It merely decomposes into other objects, that can
31  /// later be used to recompose the same object.
32  /// </summary>
33  public interface ICompositeSerializer {
34
35    /// <summary>
36    /// Defines the Priorty of this composite serializer. Higher number means
37    /// higher prioriy. Negative numbers are fallback serializers that are
38    /// disabled by default.
39    ///
40    /// All default generic composite serializers have priority 100. Specializations
41    /// have priority 200 so they will  be tried first. Priorities are
42    /// only considered for default configurations.
43    /// </summary>
44    int Priority { get; }
45
46    /// <summary>
47    /// Determines for every type whether the composite serializer is applicable.
48    /// </summary>
49    /// <param name="type">The type.</param>
50    /// <returns>
51    /// <c>true</c> if this instance can serialize the specified type; otherwise, <c>false</c>.
52    /// </returns>
53    bool CanSerialize(Type type);
54
55    /// <summary>
56    /// Give a reason if possibly why the given type cannot be serialized by this
57    /// ICompositeSerializer.
58    /// </summary>
59    /// <param name="type">The type.</param>
60    /// <returns>A string justifying why type cannot be serialized.</returns>
61    string JustifyRejection(Type type);
62
63    /// <summary>
64    /// Generate MetaInfo necessary for instance creation. (e.g. dimensions
65    /// necessary for array creation.
66    /// </summary>
67    /// <param name="obj">An object.</param>
68    /// <returns>An enumerable of <see cref="Tag"/>s.</returns>
69    IEnumerable<Tag> CreateMetaInfo(object obj);
70
71    /// <summary>
72    /// Decompose an object into <see cref="Tag"/>s, the tag name can be null,
73    /// the order in which elements are generated is guaranteed to be
74    /// the same as they will be supplied to the Populate method.
75    /// </summary>
76    /// <param name="obj">An object.</param>
77    /// <returns>An enumerable of <see cref="Tag"/>s.</returns>
78    IEnumerable<Tag> Decompose(object obj);
79
80    /// <summary>
81    /// Create an instance of the object using the provided meta information.
82    /// </summary>
83    /// <param name="type">A type.</param>
84    /// <param name="metaInfo">The meta information.</param>
85    /// <returns>A fresh instance of the provided type.</returns>
86    object CreateInstance(Type type, IEnumerable<Tag> metaInfo);
87
88    /// <summary>
89    /// Fills an object with values from the previously generated <see cref="Tag"/>s
90    /// in Decompose. The order in which the values are supplied is
91    /// the same as they where generated. <see cref="Tag"/> names might be null.
92    /// </summary>
93    /// <param name="instance">An empty object instance.</param>
94    /// <param name="tags">The tags.</param>
95    /// <param name="type">The type.</param>
96    void Populate(object instance, IEnumerable<Tag> tags, Type type);
97  }
98
99}
Note: See TracBrowser for help on using the repository browser.