Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/10/10 18:28:50 (14 years ago)
Author:
epitzer
Message:

Make StorableClass attribute compulsory for StorableSerializer to work, add named property StorableClassType to choose between Empty and MarkedOnly, later other options will be added. (#548)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableSerializer.cs

    r2993 r2994  
    99namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable {
    1010
    11   [EmptyStorableClass]
     11  /// <summary>
     12  /// Intended for serialization of all custom classes. Classes should have the
     13  /// <code>[StorableClass(StorableClassType.Empty)]</code> attribute set and a serialization mode set.
     14  /// Optionally selected fields and properties can be marked with the
     15  /// <code>[Storable]</code> attribute.
     16  /// </summary>
     17  [StorableClass(StorableClassType.Empty)]   
    1218  public class StorableSerializer : ICompositeSerializer {
    1319
     
    2026        StorableConstructorAttribute.GetStorableConstructor(type) == null)
    2127        return false;
    22       while (type != null) {
    23         if (StorableAttribute.GetStorableMembers(type, false).Count() == 0 &&
    24             !EmptyStorableClassAttribute.IsEmptyStorable(type))
    25           return false;
    26         type = type.BaseType;
    27       }
    28       return true;
     28      return StorableClassAttribute.IsStorableType(type, true);
    2929    }
    3030
     
    3333        StorableConstructorAttribute.GetStorableConstructor(type) == null)
    3434        return "no default constructor and no storable constructor";
    35       while (type != null) {
    36         if (StorableAttribute.GetStorableMembers(type, false).Count() == 0 &&
    37             !EmptyStorableClassAttribute.IsEmptyStorable(type))
    38           return string.Format("{0} has no storable members and is not marked [EmtpyStorableClass]",
    39             type);
    40         type = type.BaseType;
    41       }
    42       return "no reason";
     35      return "class or one of its base classes is not empty and has no [StorableClass(StorableClassType.Empty)] attribute";
    4336    }
    4437
     
    5952      try {
    6053        ConstructorInfo constructor = StorableConstructorAttribute.GetStorableConstructor(type);
    61         return constructor != null ? constructor.Invoke(defaultArgs) :  Activator.CreateInstance(type, true);       
     54        return constructor != null ? constructor.Invoke(defaultArgs) : Activator.CreateInstance(type, true);
    6255      } catch (TargetInvocationException x) {
    6356        throw new PersistenceException(
     
    7265      while (iter.MoveNext()) {
    7366        memberDict.Add(iter.Current.Name, iter.Current);
    74       }
     67      }     
    7568      foreach (var accessor in StorableAttribute.GetStorableAccessors(instance)) {
    7669        if (memberDict.ContainsKey(accessor.Name)) {
Note: See TracChangeset for help on using the changeset viewer.