public static IEnumerable <TreeNodeObject> EnumerateTreeNodeObjects(TreeNodeObject root = null) { var roots = ListPool <TreeNodeObject> .Get(); if (root != null) { roots.Add(root); } else { root = StudioAPI.GetSelectedObjects().FirstOrDefault()?.treeNodeObject; if (root != null) { roots.AddRange(root.GetTreeNodeCtrl().GetTreeNodeObjects()); } } foreach (var entry in roots) { yield return(entry); foreach (var tnObj in entry.child.SelectMany(EnumerateTreeNodeObjects)) { yield return(tnObj); } } ListPool <TreeNodeObject> .Release(roots); }
private IEnumerable <TreeNodeObject> EnumerateTreeNodeObjects(TreeNodeObject root = null) { var roots = new List <TreeNodeObject>(); if (root != null) { roots.Add(root); } else { root = StudioAPI.GetSelectedObjects().FirstOrDefault()?.treeNodeObject; if (root != null) { roots.AddRange(root.GetTreeNodeCtrl().GetTreeNodeObjects()); } } foreach (var entry in roots) { yield return(entry); foreach (var tnObj in entry.child.SelectMany(EnumerateTreeNodeObjects)) { yield return(tnObj); } } roots.Clear(); }