static void RemoveEditorOnlyControls(ITreeViewItem item) { var children = new List <ITreeViewItem>(item.children); (item.children as IList)?.Clear(); foreach (var child in children) { if (child is BuilderLibraryTreeItem builderLibraryTreeItem && !builderLibraryTreeItem.IsEditorOnly) { item.AddChild(child); if (child.hasChildren) { RemoveEditorOnlyControls(child); } } } }