private void ProcessVisitors(XDocument doc, IXmlVisitor visitor) { Stack <XNode> nodes = new Stack <XNode>(); if (visitor.BeginFromProject) { nodes.Push(doc.Root); } else { foreach (XNode node in doc.Root.Nodes().Reverse()) { nodes.Push(node); } } while (nodes.Any()) { XNode node = nodes.Pop(); bool @continue = visitor.Visit(node); if (!@continue) { continue; } if (node is XElement asElement) { foreach (XNode child in asElement.Nodes().Reverse()) { nodes.Push(child); } } } }
public void Accept(IXmlVisitor visitor) { visitor.Visit(this); }