Dev2.Runtime.ServiceModel.TreeEx.Descendants C# (CSharp) Method

Descendants() public static method

public static Descendants ( this root ) : IEnumerable
root this
return IEnumerable
        public static IEnumerable<IExplorerItem> Descendants(this IExplorerItem root)
        {
            var nodes = new Stack<IExplorerItem>(new[] { root });
            while(nodes.Any())
            {
                IExplorerItem node = nodes.Pop();
                yield return node;
                if(node.Children != null)
                {
                    foreach(var n in node.Children) nodes.Push(n);
                }
            }
        }
    }