/// <summary> /// Traverses from this node to each successive parent until a node with parent is reached. /// </summary> /// <param name="func"></param> public void TraverseToTop(HierarchicalViewModelAction func) { HierarchicalViewModelBase p = this; while (p != null) { func(p); p = p.Parent; } }
/// <summary> /// Visits this node, and all children recursively (i.e. It traverses the tree 'downwards' only, from parent to child). /// </summary> /// <param name="action"></param> public void Traverse(HierarchicalViewModelAction action) { if (action == null) { return; } // Firstly visit me... action(this); // then each of my children foreach (HierarchicalViewModelBase child in Children) { child.Traverse(action); } }