Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug where objects inside a package/namespace would corrupt the … #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/Core/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,12 @@ protected void LoadEntityContainers(XmlNode root)
var container = entities[containerIndex] as INestable;
foreach (XmlElement childNode in node.ChildNodes)
{
int.TryParse(childNode.InnerText, out var childIndex);
var childEntity = entities[childIndex] as INestableChild;
container.AddNestedChild(childEntity);
EntityNested?.Invoke(container, new EntityEventArgs(childEntity));
if (int.TryParse(childNode.InnerText, out var childIndex) && childIndex >= 0) // to un-corrupt old "corrupted" files
{
var childEntity = entities[childIndex] as INestableChild;
container.AddNestedChild(childEntity);
EntityNested?.Invoke(container, new EntityEventArgs(childEntity));
}
}
}
}
Expand Down Expand Up @@ -274,9 +276,14 @@ protected void SaveEntityContainers(XmlElement node)

foreach (var childEntity in ((INestable)entity).NestedChilds)
{
var childEntityNode = node.OwnerDocument.CreateElement("ChildEntity");
childEntityNode.InnerText = entities.IndexOf(childEntity).ToString();
child.AppendChild(childEntityNode);
int childEntityIndexNum = entities.IndexOf(childEntity);

if (childEntityIndexNum >= 0) // made to rule out any cases where the child entity has an index of -1
{
var childEntityNode = node.OwnerDocument.CreateElement("ChildEntity");
childEntityNode.InnerText = childEntityIndexNum.ToString();
child.AppendChild(childEntityNode);
}
}

containersNode.AppendChild(child);
Expand Down