Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3010


Ignore:
Timestamp:
03/12/10 10:43:08 (14 years ago)
Author:
epitzer
Message:

invoke storable hooks in more predictable orders, call hooks defined on base classes first. (#548)

Location:
trunk/sources/HeuristicLab.Persistence/3.3
Files:
2 edited

Legend:

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

    r2994 r3010  
    4646    }
    4747
    48     private static readonly BindingFlags instanceMembers =
    49       BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
     48    private static readonly BindingFlags declaredInstanceMembers =
     49      BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly;
    5050
    5151    private static readonly object[] emptyArgs = new object[] { };
     
    7979    }
    8080
    81     private static IEnumerable<MethodInfo> CollectHooks(HookType hookType, Type type) {     
    82       foreach (MemberInfo memberInfo in type.GetMembers(instanceMembers)) {
     81    private static IEnumerable<MethodInfo> CollectHooks(HookType hookType, Type type) { 
     82      if (type.BaseType != null)
     83        foreach (var mi in CollectHooks(hookType, type.BaseType))
     84          yield return mi;
     85      foreach (MemberInfo memberInfo in type.GetMembers(declaredInstanceMembers)) {
    8386        foreach (StorableHookAttribute hook in memberInfo.GetCustomAttributes(typeof(StorableHookAttribute), false)) {
    8487          if (hook != null && hook.HookType == hookType) {
  • trunk/sources/HeuristicLab.Persistence/3.3/Tests/UseCases.cs

    r3005 r3010  
    784784    }
    785785
     786    [StorableClass(StorableClassType.MarkedOnly)]
     787    public class HookInheritanceTestBase {
     788      [Storable]
     789      public object a;
     790      public object link;
     791      [StorableHook(HookType.AfterDeserialization)]
     792      private void relink() {
     793        link = a;
     794      }
     795    }
     796
     797    [StorableClass(StorableClassType.Empty)]
     798    public class HookInheritanceTestDerivedClass : HookInheritanceTestBase {
     799      [Storable]
     800      public object b;
     801      [StorableHook(HookType.AfterDeserialization)]
     802      private void relink() {
     803        Assert.AreSame(a, link);
     804        link = b;
     805      }
     806    }
     807
     808    [TestMethod]
     809    public void TestLinkInheritance() {
     810      HookInheritanceTestDerivedClass c = new HookInheritanceTestDerivedClass();
     811      c.a = new object();
     812      XmlGenerator.Serialize(c, tempFile);
     813      HookInheritanceTestDerivedClass newC = (HookInheritanceTestDerivedClass)XmlParser.Deserialize(tempFile);
     814      Assert.AreSame(c.b, c.link);
     815    }
     816
    786817    [ClassInitialize]
    787818    public static void Initialize(TestContext testContext) {
Note: See TracChangeset for help on using the changeset viewer.