- Timestamp:
- 03/09/10 18:14:05 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableSerializer.cs
r1960 r2980 29 29 30 30 public IEnumerable<Tag> CreateMetaInfo(object o) { 31 StorableHookAttribute.InvokeHook(HookType.BeforeSerialization, o); 31 32 return new Tag[] { }; 32 33 } … … 48 49 memberDict.Add(iter.Current.Name, iter.Current); 49 50 } 50 foreach (var accessor in StorableAttribute.GetStorableAccessors(instance)) { 51 foreach (var accessor in StorableAttribute.GetStorableAccessors(instance)) { 51 52 if (memberDict.ContainsKey(accessor.Name)) { 52 accessor.Set(memberDict[accessor.Name].Value); 53 accessor.Set(memberDict[accessor.Name].Value); 53 54 } else if (accessor.DefaultValue != null) { 54 accessor.Set(accessor.DefaultValue); 55 accessor.Set(accessor.DefaultValue); 55 56 } 56 57 } 58 StorableHookAttribute.InvokeHook(HookType.AfterDeserialization, instance); 57 59 } 58 60 } -
trunk/sources/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj
r2940 r2980 121 121 <Compile Include="Default\CompositeSerializers\Storable\EmptyStorableClassAttribute.cs" /> 122 122 <Compile Include="Default\CompositeSerializers\Storable\StorableAttribute.cs" /> 123 <Compile Include="Default\CompositeSerializers\Storable\StorableHookAttribute.cs" /> 123 124 <Compile Include="Default\CompositeSerializers\Storable\StorableSerializer.cs" /> 124 125 <Compile Include="Default\CompositeSerializers\StructSerializer.cs" /> -
trunk/sources/HeuristicLab.Persistence/3.3/Tests/UseCases.cs
r2951 r2980 659 659 } 660 660 661 private class PersistenceHooks { 662 [Storable] 663 public int a; 664 [Storable] 665 public int b; 666 public int sum; 667 public bool WasSerialized { get; private set; } 668 [StorableHook(HookType.BeforeSerialization)] 669 void PreSerializationHook() { 670 WasSerialized = true; 671 } 672 [StorableHook(HookType.AfterDeserialization)] 673 void PostDeserializationHook() { 674 sum = a + b; 675 } 676 } 677 678 [TestMethod] 679 public void HookTest() { 680 PersistenceHooks hookTest = new PersistenceHooks(); 681 hookTest.a = 2; 682 hookTest.b = 5; 683 Assert.IsFalse(hookTest.WasSerialized); 684 Assert.AreEqual(hookTest.sum, 0); 685 XmlGenerator.Serialize(hookTest, tempFile); 686 Assert.IsTrue(hookTest.WasSerialized); 687 Assert.AreEqual(hookTest.sum, 0); 688 PersistenceHooks newHookTest = (PersistenceHooks)XmlParser.Deserialize(tempFile); 689 Assert.AreEqual(newHookTest.a, hookTest.a); 690 Assert.AreEqual(newHookTest.b, hookTest.b); 691 Assert.AreEqual(newHookTest.sum, newHookTest.a + newHookTest.b); 692 Assert.IsFalse(newHookTest.WasSerialized); 693 } 694 661 695 [ClassInitialize] 662 696 public static void Initialize(TestContext testContext) {
Note: See TracChangeset
for help on using the changeset viewer.