private static ISet <string> GetNames(Declaration declaration, Predicate <Declaration> predicate) { var set = new HashSet <string>(); var stack = new Stack <Declaration>(); stack.Push(declaration); while (stack.Count > 0) { var current = stack.Pop(); if (current == null) { continue; } if (predicate(current)) { set.Add(current.Name); } foreach (var child in current.Children) { stack.Push(child); } } return(SpecializedCollections.ReadOnlySet(set)); }