Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableAttribute.cs @ 3742

Last change on this file since 3742 was 3742, checked in by gkronber, 14 years ago

Fixed GPL license headers and deleted files which are not referenced by projects. #893

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