Ejemplo n.º 1
0
        private static IEnumerable <IXmlElementSyntax> GetDescendantsInternal(SyntaxNode node, bool includeSelf)
        {
            if (includeSelf && node.IsElement())
            {
                yield return((IXmlElementSyntax)node);
            }

            var childStack = new Stack <SyntaxNode>();

            childStack.Push(node);

            while (childStack.Count > 0)
            {
                var c = childStack.Pop();
                for (int i = c.GreenNode.SlotCount - 1; i >= 0; i--)
                {
                    var child = c.GetNodeSlot(i);
                    if (child != null)
                    {
                        childStack.Push(child);
                    }
                }
                if (childStack.Count > 0)
                {
                    var stackTop = childStack.Peek();
                    if (stackTop != null && stackTop.IsElement())
                    {
                        yield return((IXmlElementSyntax)stackTop);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static IEnumerable <IXmlElementSyntax> GetAncestorsInternal(SyntaxNode node, bool includeSelf)
        {
            if (includeSelf && node.IsElement())
            {
                yield return((IXmlElementSyntax)node);
            }

            var parent = node.ParentElement;

            while (parent != null)
            {
                yield return(parent);

                parent = parent.Parent;
            }
        }