- Timestamp:
- 03/10/10 18:28:50 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers
- Files:
-
- 1 added
- 1 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/ArraySerializer.cs
r2993 r2994 8 8 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 9 9 10 [ EmptyStorableClass]10 [StorableClass(StorableClassType.Empty)] 11 11 public class ArraySerializer : ICompositeSerializer { 12 12 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/CompactNumberArray2StringSerializer.cs
r2993 r2994 10 10 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 11 11 12 [ EmptyStorableClass]12 [StorableClass(StorableClassType.Empty)] 13 13 public class CompactNumberArray2StringSerializer : ICompositeSerializer { 14 14 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/DictionarySerializer.cs
r2993 r2994 9 9 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 10 10 11 [ EmptyStorableClass]11 [StorableClass(StorableClassType.Empty)] 12 12 public class DictionarySerializer : ICompositeSerializer { 13 13 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/EnumSerializer.cs
r2993 r2994 7 7 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 8 8 9 [ EmptyStorableClass]9 [StorableClass(StorableClassType.Empty)] 10 10 public class EnumSerializer : ICompositeSerializer { 11 11 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/EnumerableSerializer.cs
r2993 r2994 10 10 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 11 11 12 [ EmptyStorableClass]12 [StorableClass(StorableClassType.Empty)] 13 13 public class EnumerableSerializer : ICompositeSerializer { 14 14 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/KeyValuePairSerializer.cs
r2993 r2994 9 9 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 10 10 11 [ EmptyStorableClass]11 [StorableClass(StorableClassType.Empty)] 12 12 public class KeyValuePairSerializer : ICompositeSerializer { 13 13 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Number2StringSerializer.cs
r2993 r2994 12 12 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 13 13 14 [ EmptyStorableClass]14 [StorableClass(StorableClassType.Empty)] 15 15 public class Number2StringSerializer : ICompositeSerializer { 16 16 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/NumberEnumerable2StringSerializer.cs
r2993 r2994 11 11 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 12 12 13 [ EmptyStorableClass]13 [StorableClass(StorableClassType.Empty)] 14 14 public class NumberEnumerable2StringSerializer : ICompositeSerializer { 15 15 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/StackSerializer.cs
r2993 r2994 10 10 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 11 11 12 [ EmptyStorableClass]12 [StorableClass(StorableClassType.Empty)] 13 13 public class StackSerializer : ICompositeSerializer { 14 14 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableAttribute.cs
r2991 r2994 7 7 namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable { 8 8 9 10 /// <summary> 11 /// Mark the member of a class to be considered by the <code>StorableSerializer</code>. 12 /// The class must be marked as <code>[StorableClass(StorableClassType.Empty)]</code> and the 13 /// <code>StorableClassType</code> should be set to <code>MarkedOnly</code> for 14 /// this attribute to kick in. 15 /// </summary> 9 16 [AttributeUsage( 10 17 AttributeTargets.Field | AttributeTargets.Property, 11 18 AllowMultiple = false, 12 Inherited = false)] 19 Inherited = false)] 13 20 public class StorableAttribute : Attribute { 14 21 22 /// <summary> 23 /// An optional name for this member that will be used during serialization. 24 /// 25 /// This allows to rename a field/property in code but still be able to read 26 /// the old serialized format. 27 /// </summary> 15 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> 16 36 public object DefaultValue { get; set; } 17 37 … … 83 103 private static MemberCache memberCache = new MemberCache(); 84 104 105 106 /// <summary> 107 /// Get all fields and properties of a class that have the 108 /// <code>[Storable]</code> attribute set. 109 /// </summary> 85 110 public static IEnumerable<StorableMemberInfo> GetStorableMembers(Type type) { 86 111 return GetStorableMembers(type, true); 87 112 } 88 113 114 /// <summary> 115 /// Get all fields and properties of a class that have the 116 /// <code>[Storable]</code> attribute set. 117 /// </summary> 118 /// <param name="inherited">should storable members from base classes be included</param> 89 119 public static IEnumerable<StorableMemberInfo> GetStorableMembers(Type type, bool inherited) { 90 120 lock (memberCache) { … … 110 140 } 111 141 142 143 /// <summary> 144 /// Get the associated accessors for all storable memebrs. 145 /// </summary> 146 /// <param name="obj"></param> 147 /// <returns></returns> 112 148 public static IEnumerable<DataMemberAccessor> GetStorableAccessors(object obj) { 113 149 foreach (var memberInfo in GetStorableMembers(obj.GetType())) -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableConstructorAttribute.cs
r2991 r2994 8 8 namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable { 9 9 10 11 /// <summary> 12 /// Indicate that this constructor should be used instead of the default constructor 13 /// when the <code>StorableSerializer</code> instantiates this class during 14 /// deserialization. 15 /// 16 /// The constructor must take exactly one <code>bool</code> argument that will be 17 /// set to <code>true</code> during deserialization. 18 /// </summary> 10 19 [AttributeUsage(AttributeTargets.Constructor, Inherited = false, AllowMultiple = false)] 11 20 public sealed class StorableConstructorAttribute : Attribute { … … 17 26 new Dictionary<Type, ConstructorInfo>(); 18 27 28 29 /// <summary> 30 /// Get a designated storable constructor for a type or <code>null</code>. 31 /// </summary> 19 32 public static ConstructorInfo GetStorableConstructor(Type type) { 20 33 lock (constructorCache) { -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableHookAttribute.cs
r2991 r2994 7 7 namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable { 8 8 9 10 /// <summary> 11 /// Indicates the time at which the hook should be invoked. 12 /// </summary> 9 13 public enum HookType { BeforeSerialization, AfterDeserialization }; 10 14 11 [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] 15 16 /// <summary> 17 /// Mark methods that should be called at certain times during 18 /// serialization/deserialization by the <code>StorableSerializer</code>. 19 /// </summary> 20 [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)] 12 21 public sealed class StorableHookAttribute : Attribute { 13 22 … … 27 36 } 28 37 38 39 /// <summary> 40 /// Mark method as <code>StorableSerializer</code> hook to be run 41 /// at the <code>HookType</code> time. 42 /// </summary> 43 /// <param name="hookType"></param> 29 44 public StorableHookAttribute(HookType hookType) { 30 45 this.hookType = hookType; … … 39 54 new Dictionary<HookDesignator, List<MethodInfo>>(); 40 55 56 57 /// <summary> 58 /// Invoke <code>hookType</code> hook on <code>obj</code>. 59 /// </summary> 41 60 public static void InvokeHook(HookType hookType, object obj) { 42 61 if (obj == null) … … 45 64 mi.Invoke(obj, emptyArgs); 46 65 } 47 } 66 } 48 67 49 68 private static IEnumerable<MethodInfo> GetHooks(HookType hookType, Type type) { -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableSerializer.cs
r2993 r2994 9 9 namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable { 10 10 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)] 12 18 public class StorableSerializer : ICompositeSerializer { 13 19 … … 20 26 StorableConstructorAttribute.GetStorableConstructor(type) == null) 21 27 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); 29 29 } 30 30 … … 33 33 StorableConstructorAttribute.GetStorableConstructor(type) == null) 34 34 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"; 43 36 } 44 37 … … 59 52 try { 60 53 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); 62 55 } catch (TargetInvocationException x) { 63 56 throw new PersistenceException( … … 72 65 while (iter.MoveNext()) { 73 66 memberDict.Add(iter.Current.Name, iter.Current); 74 } 67 } 75 68 foreach (var accessor in StorableAttribute.GetStorableAccessors(instance)) { 76 69 if (memberDict.ContainsKey(accessor.Name)) { -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/StructSerializer.cs
r2993 r2994 10 10 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 11 11 12 [ EmptyStorableClass]12 [StorableClass(StorableClassType.Empty)] 13 13 public class StructSerializer : ICompositeSerializer { 14 14 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/TypeSerializer.cs
r2993 r2994 8 8 namespace HeuristicLab.Persistence.Default.CompositeSerializers { 9 9 10 [ EmptyStorableClass]10 [StorableClass(StorableClassType.Empty)] 11 11 public class TypeSerializer : ICompositeSerializer { 12 12
Note: See TracChangeset
for help on using the changeset viewer.