private void Visit(IWizardPage node) { if (First == null && node != rootNode) { First = node; } // Would update the Last node everytime, but if the only // node is the root node, then this will be wrong. if (node != rootNode) { Last = node; } if (!found) { if (node.Equals(nodeToFind)) { found = true; } else { // Whilst not found, keep updating previous, last update // will be the one before the searched for node! if (node != rootNode) { previous = node; } } } else { if (Next == null) { Next = node; } } foreach (var child in node.Children) { Visit(child); } }