예제 #1
0
        /// <summary>
        /// Walks through the tree, and calls the handler for each node.
        /// </summary>
        /// <param name="handler">The method to be called for each nodes</param>
        public void Walk(WalkHandler handler)
        {
            List <Element> ancestors = new List <Element>();

            handler?.Invoke(this, ancestors);

            Walk(this, ancestors, handler);
        }
예제 #2
0
        private void Walk(Element parent, List <Element> ancestors, WalkHandler handler)
        {
            if (parent.children != null)
            {
                List <Element> _ancestors = new List <Element>(ancestors)
                {
                    parent
                };

                foreach (Element child in parent.children)
                {
                    handler?.Invoke(child, _ancestors);
                    Walk(child, _ancestors, handler);
                }
            }
        }