//public static void SetForCascadingDeletion(this IGuidTreeItem guidTreeItem) //{ // //Recursive loop detection // if(guidTreeItem.PendingDeletion) // return; //We have been here before // guidTreeItem.PendingDeletion = true; // //Recurse down the tree // foreach (var child in guidTreeItem.Children) // { // child.Parent = null; // child.SetForCascadingDeletion(); // } //} public static void SetParentLinkForChildren(this IGuidTreeItem guidTreeItem) { if (guidTreeItem.Children == null) { return; } foreach (var child in guidTreeItem.Children) { child.Parent = guidTreeItem; child.UpdateAncestry(); //Recurse child.SetParentLinkForChildren(); } }
public static string GetAncestry(this IGuidTreeItem guidTreeItem) { var ancestry = new List <IGuidTreeItem>(); var currentStage = guidTreeItem; while (currentStage != null) { if (ancestry.Contains(currentStage)) { throw new StackOverflowException("The current tree structure contains a loop"); } ancestry.Add(currentStage); currentStage = currentStage.Parent; } return(BuildAcestryString(ancestry)); }
public static void UpdateAncestry(this IGuidTreeItem guidTreeItem) { guidTreeItem.Ancestry = guidTreeItem.GetAncestry(); }