private TreeNode ConvertToTreeNode(CobolTreeNode cobolTreeNode, string query = "") { var result = new TreeNode(cobolTreeNode.Name); foreach (var treeNode in cobolTreeNode.GetNodes()) { var node = ConvertToTreeNode(treeNode, query); // if query is empty, match or Nodes contains match if (string.IsNullOrWhiteSpace(query) || node.Text.ContainsIgnoreCase(query) || node.Nodes.Count > 0) { result.Nodes.Add(node); } } return(result); }
private IEnumerable <TreeNode> Flatten(CobolTreeNode parent, bool ignoreFirst = false, string query = "") { if (!ignoreFirst) { yield return(new TreeNode(parent.Name)); } foreach (var child in parent.GetNodes()) // check null if you must { foreach (var relative in Flatten(child, query: query)) { if ((string.IsNullOrWhiteSpace(query) || relative.Text.ContainsIgnoreCase(query)) && child.Name != relative.Name) { yield return(new TreeNode(relative.Text)); } } } }