Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/26/10 15:46:10 (15 years ago)
Author:
epitzer
Message:

Always instantiate parent before processing an inner composite. (#888)

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

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs

    r1859 r2873  
    117117    }
    118118
     119    private void InstantiateParent() {
     120      if (parentStack.Count == 0)
     121        return;
     122      Midwife m = parentStack.Peek();
     123      if (!m.MetaMode && m.Obj == null)
     124        CreateInstance(m);
     125    }
     126
    119127    private void CompositeStartHandler(BeginToken token) {
     128      InstantiateParent();
    120129      Type type = typeIds[(int)token.TypeId];
    121130      try {
     
    193202      } else {
    194203        Midwife m = parentStack.Peek();
    195         if (m.MetaMode == false && m.Obj == null)
     204        if (m.MetaMode == false && m.Obj == null) {
    196205          CreateInstance(m);
     206        }
    197207        m.AddValue(name, value);
    198208      }
  • trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs

    r2859 r2873  
    581581    }
    582582
     583    class Child {
     584      [Storable]
     585      public GrandParent grandParent;
     586    }
     587
     588    class Parent {
     589      [Storable]
     590      public Child child;
     591    }
     592
     593    class GrandParent {
     594      [Storable]
     595      public Parent parent;
     596    }
     597
     598    [TestMethod]
     599    public void InstantiateParentChainReference() {
     600      GrandParent gp = new GrandParent();
     601      gp.parent = new Parent();
     602      gp.parent.child = new Child();
     603      gp.parent.child.grandParent = gp;
     604      Assert.AreSame(gp, gp.parent.child.grandParent);
     605      XmlGenerator.Serialize(gp, tempFile);
     606      GrandParent newGp = (GrandParent)XmlParser.Deserialize(tempFile);
     607      Assert.AreSame(newGp, newGp.parent.child.grandParent);
     608    }
     609
    583610    [ClassInitialize]
    584611    public static void Initialize(TestContext testContext) {
Note: See TracChangeset for help on using the changeset viewer.