Changeset 2994 for trunk/sources/HeuristicLab.Persistence
- Timestamp:
- 03/10/10 18:28:50 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3
- Files:
-
- 1 added
- 1 deleted
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Core/Configuration.cs ¶
r1823 r2994 6 6 namespace HeuristicLab.Persistence.Core { 7 7 8 [StorableClass(StorableClassType.MarkedOnly)] 8 9 public class Configuration { 9 10 … … 17 18 [Storable] 18 19 public IFormat Format { get; private set; } 19 20 20 21 private Configuration() { 21 22 compositeSerializerCache = new Dictionary<Type, ICompositeSerializer>(); -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Core/FormatBase.cs ¶
r1853 r2994 4 4 namespace HeuristicLab.Persistence.Interfaces { 5 5 6 [ EmptyStorableClass]6 [StorableClass(StorableClassType.Empty)] 7 7 public abstract class FormatBase<SerialDataFormat> : IFormat<SerialDataFormat> where SerialDataFormat : ISerialData { 8 8 -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Core/PrimitiveSerializerBase.cs ¶
r1853 r2994 5 5 namespace HeuristicLab.Persistence.Interfaces { 6 6 7 [ EmptyStorableClass]7 [StorableClass(StorableClassType.Empty)] 8 8 public abstract class PrimitiveSerializerBase<Source, SerialData> : 9 9 IPrimitiveSerializer<Source, SerialData> -
TabularUnified 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 -
TabularUnified 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 -
TabularUnified 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 -
TabularUnified 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 -
TabularUnified 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 -
TabularUnified 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 -
TabularUnified 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 -
TabularUnified 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 -
TabularUnified 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 -
TabularUnified 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())) -
TabularUnified 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) { -
TabularUnified 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) { -
TabularUnified 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)) { -
TabularUnified 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 -
TabularUnified 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 -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Default/DebugString/DebugString.cs ¶
r1823 r2994 10 10 namespace HeuristicLab.Persistence.Default.DebugString { 11 11 12 [StorableClass(StorableClassType.MarkedOnly)] 12 13 public class DebugString : ISerialData { 13 14 -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Default/DebugString/DebugStringFormat.cs ¶
r1823 r2994 10 10 namespace HeuristicLab.Persistence.Default.DebugString { 11 11 12 [ EmptyStorableClass]12 [StorableClass(StorableClassType.Empty)] 13 13 public class DebugStringFormat : FormatBase<DebugString> { 14 14 public override string Name { get { return "DebugString"; } } -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberArray2XmlSerializerBase.cs ¶
r1853 r2994 8 8 namespace HeuristicLab.Persistence.Default.Xml.Compact { 9 9 10 [ EmptyStorableClass]10 [StorableClass(StorableClassType.Empty)] 11 11 public abstract class NumberArray2XmlSerializerBase<T> : CompactXmlSerializerBase<T> where T : class { 12 12 -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberEnumeration2XmlSerializerBase.cs ¶
r1853 r2994 8 8 namespace HeuristicLab.Persistence.Default.Xml.Compact { 9 9 10 [ EmptyStorableClass]10 [StorableClass(StorableClassType.Empty)] 11 11 public abstract class NumberEnumeration2XmlSerializerBase<T> : CompactXmlSerializerBase<T> where T : IEnumerable { 12 12 -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlFormat.cs ¶
r1823 r2994 5 5 namespace HeuristicLab.Persistence.Default.Xml { 6 6 7 [ EmptyStorableClass]7 [StorableClass(StorableClassType.Empty)] 8 8 public class XmlFormat : FormatBase<XmlString> { 9 9 public override string Name { get { return "XML"; } } -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlString.cs ¶
r1823 r2994 6 6 namespace HeuristicLab.Persistence.Default.Xml { 7 7 8 [StorableClass(StorableClassType.MarkedOnly)] 8 9 public class XmlString : ISerialData { 9 10 -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj ¶
r2983 r2994 119 119 <Compile Include="Default\CompositeSerializers\StackSerializer.cs" /> 120 120 <Compile Include="Default\CompositeSerializers\Storable\DataMemberAccessor.cs" /> 121 <Compile Include="Default\CompositeSerializers\Storable\ EmptyStorableClassAttribute.cs" />121 <Compile Include="Default\CompositeSerializers\Storable\StorableClassAttribute.cs" /> 122 122 <Compile Include="Default\CompositeSerializers\Storable\StorableAttribute.cs" /> 123 123 <Compile Include="Default\CompositeSerializers\Storable\StorableConstructorAttribute.cs" /> -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Tests/StorableAttributeTests.cs ¶
r2951 r2994 8 8 namespace HeuristicLab.Persistence_33.Tests { 9 9 10 [StorableClass(StorableClassType.MarkedOnly)] 10 11 class DemoClass { 11 12 … … 20 21 } 21 22 23 [StorableClass(StorableClassType.MarkedOnly)] 22 24 class Base { 23 25 public string baseName; … … 29 31 } 30 32 33 [StorableClass(StorableClassType.MarkedOnly)] 31 34 class Override : Base { 32 35 [Storable] … … 37 40 } 38 41 39 [ EmptyStorableClass]42 [StorableClass(StorableClassType.Empty)] 40 43 class Intermediate : Override { 41 44 } 42 45 46 [StorableClass(StorableClassType.MarkedOnly)] 43 47 class New : Intermediate { 44 48 public string newName; -
TabularUnified trunk/sources/HeuristicLab.Persistence/3.3/Tests/UseCases.cs ¶
r2993 r2994 21 21 namespace HeuristicLab.Persistence_33.Tests { 22 22 23 [StorableClass(StorableClassType.MarkedOnly)] 23 24 public class NumberTest { 24 25 [Storable] … … 42 43 } 43 44 45 [StorableClass(StorableClassType.MarkedOnly)] 44 46 public class NonDefaultConstructorClass { 45 47 [Storable] … … 50 52 } 51 53 54 [StorableClass(StorableClassType.MarkedOnly)] 52 55 public class IntWrapper { 53 56 … … 72 75 } 73 76 77 [StorableClass(StorableClassType.MarkedOnly)] 74 78 public class PrimitivesTest : NumberTest { 75 79 [Storable] … … 86 90 public enum TestEnum { va1, va2, va3, va8 } ; 87 91 92 [StorableClass(StorableClassType.MarkedOnly)] 88 93 public class RootBase { 89 94 [Storable] … … 93 98 } 94 99 100 [StorableClass(StorableClassType.MarkedOnly)] 95 101 public class Root : RootBase { 96 102 [Storable] … … 127 133 public enum TrickyEnum { zero = 0, one = 1, two = 2 } 128 134 135 [StorableClass(StorableClassType.MarkedOnly)] 129 136 public class EnumTest { 130 137 [Storable] … … 136 143 } 137 144 145 [StorableClass(StorableClassType.MarkedOnly)] 138 146 public class Custom { 139 147 [Storable] … … 145 153 } 146 154 155 [StorableClass(StorableClassType.MarkedOnly)] 147 156 public class Manager { 148 157 … … 157 166 } 158 167 168 [StorableClass(StorableClassType.MarkedOnly)] 159 169 public class C { 160 170 [Storable] … … 353 363 } 354 364 365 [StorableClass(StorableClassType.MarkedOnly)] 355 366 public class NestedType { 356 367 [Storable] … … 582 593 } 583 594 595 [StorableClass(StorableClassType.MarkedOnly)] 584 596 class Child { 585 597 [Storable] … … 587 599 } 588 600 601 [StorableClass(StorableClassType.MarkedOnly)] 589 602 class Parent { 590 603 [Storable] … … 592 605 } 593 606 607 [StorableClass(StorableClassType.MarkedOnly)] 594 608 class GrandParent { 595 609 [Storable] … … 659 673 } 660 674 675 [StorableClass(StorableClassType.MarkedOnly)] 661 676 private class PersistenceHooks { 662 677 [Storable] … … 693 708 } 694 709 695 [ EmptyStorableClass]710 [StorableClass(StorableClassType.Empty)] 696 711 private class CustomConstructor { 697 712 public string Value = "none"; … … 715 730 } 716 731 717 [ EmptyStorableClass]732 [StorableClass(StorableClassType.Empty)] 718 733 public class ExplodingDefaultConstructor { 719 734 public ExplodingDefaultConstructor() {
Note: See TracChangeset
for help on using the changeset viewer.