1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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;
|
---|
23 | using System.Text;
|
---|
24 |
|
---|
25 | namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable {
|
---|
26 |
|
---|
27 |
|
---|
28 | /// <summary>
|
---|
29 | /// Mark the member of a class to be considered by the <c>StorableSerializer</c>.
|
---|
30 | /// The class must be marked as <c>[StorableClass]</c> and the
|
---|
31 | /// <c>StorableClassType</c> should be set to <c>MarkedOnly</c> for
|
---|
32 | /// this attribute to kick in.
|
---|
33 | /// </summary>
|
---|
34 | [AttributeUsage(
|
---|
35 | AttributeTargets.Field | AttributeTargets.Property,
|
---|
36 | AllowMultiple = false,
|
---|
37 | Inherited = false)]
|
---|
38 | public class StorableAttribute : Attribute {
|
---|
39 |
|
---|
40 | /// <summary>
|
---|
41 | /// An optional name for this member that will be used during serialization.
|
---|
42 | /// This allows to rename a field/property in code but still be able to read
|
---|
43 | /// the old serialized format.
|
---|
44 | /// </summary>
|
---|
45 | /// <value>The name.</value>
|
---|
46 | public string Name { get; set; }
|
---|
47 |
|
---|
48 |
|
---|
49 | /// <summary>
|
---|
50 | /// A default value in case the field/property was not present or not serialized
|
---|
51 | /// in a previous version of the class and could therefore be absent during
|
---|
52 | /// deserialization.
|
---|
53 | /// </summary>
|
---|
54 | /// <value>The default value.</value>
|
---|
55 | public object DefaultValue { get; set; }
|
---|
56 |
|
---|
57 | /// <summary>
|
---|
58 | /// Allow storable attribute on properties with only a getter or a setter. These
|
---|
59 | /// properties will then by either only serialized but not deserialized or only
|
---|
60 | /// deserialized (if stored) but not serialized again.
|
---|
61 | /// </summary>
|
---|
62 | public bool AllowOneWay { get; set; }
|
---|
63 |
|
---|
64 | /// <summary>
|
---|
65 | /// Returns a <see cref="System.String"/> that represents this instance.
|
---|
66 | /// </summary>
|
---|
67 | /// <returns>
|
---|
68 | /// A <see cref="System.String"/> that represents this instance.
|
---|
69 | /// </returns>
|
---|
70 | public override string ToString() {
|
---|
71 | StringBuilder sb = new StringBuilder();
|
---|
72 | sb.Append("[Storable");
|
---|
73 | if (Name != null || DefaultValue != null)
|
---|
74 | sb.Append('(');
|
---|
75 | if (Name != null) {
|
---|
76 | sb.Append("Name = \"").Append(Name).Append("\"");
|
---|
77 | if (DefaultValue != null)
|
---|
78 | sb.Append(", ");
|
---|
79 | }
|
---|
80 | if (DefaultValue != null)
|
---|
81 | sb.Append("DefaultValue = \"").Append(DefaultValue).Append("\"");
|
---|
82 | if (Name != null || DefaultValue != null)
|
---|
83 | sb.Append(')');
|
---|
84 | sb.Append(']');
|
---|
85 | return sb.ToString();
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|