There is a certain base class representing a node of an element tree:
class TreeITem { public bool Enabled {get;set;} }
E has two of his heirs: a regular node and a directory (which has ITreeItem
type ITreeItem
). In general, it turns out something like folders and files.
File class:
class FileItem : TreeItem { ... }
Folder class:
class FolderItem : TreeItem { .... public Collection<ITreeItem> SubItems {get;set;} }
And ultimately we will work with the TreeItem collection:
Collection<TreeItem> AllItems
The question is: how to find all instances inherited by TreeItem
in AllItems
with, say, the Enabled == true
field Enabled == true
using LINQ
? I tried using SelectMany
, but something does not work at all - I take out the elements of the first and second level, but it does not go any further.
In general, the question boils down to how to pull this tree into the list, and there it is no problem to find one of them by condition. Interests option through LINQ
FolderItem
type, and in turn, there is also a collection of sub-elements, and there can also be aFolderItem
. Duck, I want to get them all - DonilFileItem
(it has no children) orFolderItem
(it can have elements likeFileItem
orFolderItem
) and so on. So I want to get all the elements, regardless of the level of nesting. So clearer? Find all the files and folders in the directory where the fieldEnabled = true
no matter how deeply they lie - this is if you have an anology with files / folders - Donil