[3742] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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 |
|
---|
| 22 | using System;
|
---|
[1454] | 23 | using System.Collections.Generic;
|
---|
| 24 | using HeuristicLab.Persistence.Core;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.Persistence.Interfaces {
|
---|
| 27 |
|
---|
[3016] | 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>
|
---|
[1823] | 33 | public interface ICompositeSerializer {
|
---|
[1454] | 34 |
|
---|
| 35 | /// <summary>
|
---|
[1823] | 36 | /// Defines the Priorty of this composite serializer. Higher number means
|
---|
[3016] | 37 | /// higher prioriy. Negative numbers are fallback serializers that are
|
---|
| 38 | /// disabled by default.
|
---|
| 39 | ///
|
---|
[1823] | 40 | /// All default generic composite serializers have priority 100. Specializations
|
---|
[1539] | 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>
|
---|
[1823] | 47 | /// Determines for every type whether the composite serializer is applicable.
|
---|
[3016] | 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>
|
---|
[1823] | 53 | bool CanSerialize(Type type);
|
---|
[1454] | 54 |
|
---|
| 55 | /// <summary>
|
---|
[2993] | 56 | /// Give a reason if possibly why the given type cannot be serialized by this
|
---|
| 57 | /// ICompositeSerializer.
|
---|
| 58 | /// </summary>
|
---|
[3016] | 59 | /// <param name="type">The type.</param>
|
---|
| 60 | /// <returns>A string justifying why type cannot be serialized.</returns>
|
---|
[2993] | 61 | string JustifyRejection(Type type);
|
---|
| 62 |
|
---|
| 63 | /// <summary>
|
---|
[3016] | 64 | /// Generate MetaInfo necessary for instance creation. (e.g. dimensions
|
---|
[3036] | 65 | /// necessary for array creation.
|
---|
[3016] | 66 | /// </summary>
|
---|
| 67 | /// <param name="obj">An object.</param>
|
---|
| 68 | /// <returns>An enumerable of <see cref="Tag"/>s.</returns>
|
---|
[1553] | 69 | IEnumerable<Tag> CreateMetaInfo(object obj);
|
---|
| 70 |
|
---|
| 71 | /// <summary>
|
---|
[3016] | 72 | /// Decompose an object into <see cref="Tag"/>s, the tag name can be null,
|
---|
[1454] | 73 | /// the order in which elements are generated is guaranteed to be
|
---|
[1553] | 74 | /// the same as they will be supplied to the Populate method.
|
---|
[3016] | 75 | /// </summary>
|
---|
| 76 | /// <param name="obj">An object.</param>
|
---|
| 77 | /// <returns>An enumerable of <see cref="Tag"/>s.</returns>
|
---|
[1542] | 78 | IEnumerable<Tag> Decompose(object obj);
|
---|
[1454] | 79 |
|
---|
| 80 | /// <summary>
|
---|
[1553] | 81 | /// Create an instance of the object using the provided meta information.
|
---|
[1454] | 82 | /// </summary>
|
---|
[3016] | 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>
|
---|
[1553] | 86 | object CreateInstance(Type type, IEnumerable<Tag> metaInfo);
|
---|
[1454] | 87 |
|
---|
| 88 | /// <summary>
|
---|
[3016] | 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>
|
---|
[1553] | 96 | void Populate(object instance, IEnumerable<Tag> tags, Type type);
|
---|
[1566] | 97 | }
|
---|
[1454] | 98 |
|
---|
| 99 | } |
---|