Hello,
While iterating through nodes, I wanted to create a NodeCollection in order to remember the nodes i have already treated, however i don’t know which class derives from NodeCollection, what can i use ?
The collection should be able to contain any kind of node, like the one you get when calling
GetChildNodes(NodeType.Any
Sincerely.
@guyyyyyyyyyyy You can use System.Collections.Generic.List<Node>
.
Thank you for your answer
More precisely, I need to check if a node is already in a collection of nodes or in their children, is there a structure that can do that or do i have to implement it ?
@guyyyyyyyyyyy I am afraid there is no such structure. In System.Collections.Generic.List<Node>
you can use Contains
method to check whether the list already contains the node. You can use LINQ to check whether the node is a child of the nodes in the collection. Something like this:
bool contsinNode = collection
.Where(n => nodeToCheck.Equals(n) || (n.IsComposite ? (n as CompositeNode).GetChildNodes(NodeType.Any, true).Contains(nodeToCheck) : false) )
.Any();
1 Like