Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3036 was 3025, checked in by epitzer, 15 years ago

Move attribute discovery from attribute classes to StorableSerializer (in preparation for unified discovery and handling of AllFields, AllProperties, ...) (#548)

File size: 2.1 KB
Line 
1using System;
2using System.Linq;
3using System.Collections.Generic;
4using System.Reflection;
5using System.Text;
6
7namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable {
8
9
10  /// <summary>
11  /// Mark the member of a class to be considered by the <c>StorableSerializer</c>.
12  /// The class must be marked as <c>[StorableClass]</c> and the
13  /// <c>StorableClassType</c> should be set to <c>MarkedOnly</c> for
14  /// this attribute to kick in.
15  /// </summary>
16  [AttributeUsage(
17    AttributeTargets.Field | AttributeTargets.Property,
18    AllowMultiple = false,
19    Inherited = false)]   
20  public class StorableAttribute : Attribute {
21
22    /// <summary>
23    /// An optional name for this member that will be used during serialization.
24    /// This allows to rename a field/property in code but still be able to read
25    /// the old serialized format.
26    /// </summary>
27    /// <value>The name.</value>
28    public string Name { get; set; }
29
30
31    /// <summary>
32    /// A default value in case the field/property was not present or not serialized
33    /// in a previous version of the class and could therefore be absent during
34    /// deserialization.
35    /// </summary>
36    /// <value>The default value.</value>
37    public object DefaultValue { get; set; }
38
39    /// <summary>
40    /// Returns a <see cref="System.String"/> that represents this instance.
41    /// </summary>
42    /// <returns>
43    /// A <see cref="System.String"/> that represents this instance.
44    /// </returns>
45    public override string ToString() {
46      StringBuilder sb = new StringBuilder();
47      sb.Append("[Storable");
48      if (Name != null || DefaultValue != null)
49        sb.Append('(');
50      if (Name != null) {
51        sb.Append("Name = \"").Append(Name).Append("\"");
52        if (DefaultValue != null)
53          sb.Append(", ");
54      }
55      if (DefaultValue != null)
56        sb.Append("DefaultValue = \"").Append(DefaultValue).Append("\"");
57      if (Name != null || DefaultValue != null)
58        sb.Append(')');
59      sb.Append(']');
60      return sb.ToString();
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.