public static void PopulateWithFilteredNodes(ref FolderTreeNode folder) { var components = folder.Folder; foreach (var component in components.Children.ComponentCollection .Where(c => (c.Impl as GME.MGA.IMgaModel).GetChildrenOfKind(typeof(CyPhy.ModelicaModel).Name).Count + (c.Impl as GME.MGA.IMgaModel).GetChildrenOfKind(typeof(CyPhy.CyberModel).Name).Count > 0)) { folder.Children.Add(new ComponentTreeNode(component)); } foreach (var subComponents in components.Children.ComponentsCollection.Where(f => FolderHasModelicaComponents(f))) { var subFolder = new FolderTreeNode(subComponents); folder.Children.Add(subFolder); PopulateWithFilteredNodes(ref subFolder); } }