Class TreeNodeExtensions
- Namespace
- LfrlAnvil.Collections.Extensions
- Assembly
- LfrlAnvil.Collections.dll
Contains ITreeNode<T> extension methods.
public static class TreeNodeExtensions
- Inheritance
-
TreeNodeExtensions
- Inherited Members
Methods
GetChildIndex<T>(ITreeNode<T>, ITreeNode<T>)
Finds a 0-based index of the provided node in the Children collection
of the specified parent.
[Pure]
public static int GetChildIndex<T>(this ITreeNode<T> parent, ITreeNode<T> node)
Parameters
Returns
- int
0-based index of the provided
nodeif it exists, otherwise -1.
Type Parameters
TValue type.
GetLevel<T>(ITreeNode<T>)
Calculates the depth of the provided node.
[Pure]
public static int GetLevel<T>(this ITreeNode<T> node)
Parameters
nodeITreeNode<T>Node to check.
Returns
- int
Node's depth. 0 means that the node is a root node.
Type Parameters
TValue type.
GetLevel<T>(ITreeNode<T>, ITreeNode<T>)
Calculates the depth of the provided node relative to the specified root.
[Pure]
public static int GetLevel<T>(this ITreeNode<T> node, ITreeNode<T> root)
Parameters
Returns
- int
Node's depth relative to the
rootnode. 0 means that the node is therootnode. -1 means that the node is not a descendant of therootnode.
Type Parameters
TValue type.
GetRoot<T>(ITreeNode<T>)
Finds the root node.
[Pure]
public static ITreeNode<T> GetRoot<T>(this ITreeNode<T> node)
Parameters
nodeITreeNode<T>Source node.
Returns
- ITreeNode<T>
Root node or the provided
nodeif it is a root node.
Type Parameters
TValue type.
IsAncestorOf<T>(ITreeNode<T>, ITreeNode<T>)
Checks whether or not the provided ancestor is an ancestor node of the specified node.
[Pure]
public static bool IsAncestorOf<T>(this ITreeNode<T> ancestor, ITreeNode<T> node)
Parameters
Returns
- bool
true when the provided
ancestoris an ancestor node ofnode, otherwise false.
Type Parameters
TValue type.
IsChildOf<T>(ITreeNode<T>, ITreeNode<T>)
Checks whether or not the provided node is a direct child node of the specified parent.
[Pure]
public static bool IsChildOf<T>(this ITreeNode<T> node, ITreeNode<T> parent)
Parameters
Returns
- bool
true when the provided
nodeis a child node ofparent, otherwise false.
Type Parameters
TValue type.
IsDescendantOf<T>(ITreeNode<T>, ITreeNode<T>)
Checks whether or not the provided node is a descendant node of the specified ancestor.
[Pure]
public static bool IsDescendantOf<T>(this ITreeNode<T> node, ITreeNode<T> ancestor)
Parameters
Returns
- bool
true when the provided
nodeis a descendant node ofancestor, otherwise false.
Type Parameters
TValue type.
IsLeaf<T>(ITreeNode<T>)
Checks whether or not the provided node is a leaf node.
[Pure]
public static bool IsLeaf<T>(this ITreeNode<T> node)
Parameters
nodeITreeNode<T>Node to check.
Returns
- bool
true when the node is a leaf node (does not have any children nodes), otherwise false.
Type Parameters
TValue type.
IsParentOf<T>(ITreeNode<T>, ITreeNode<T>)
Checks whether or not the provided parent is a parent node of the specified node.
[Pure]
public static bool IsParentOf<T>(this ITreeNode<T> parent, ITreeNode<T> node)
Parameters
Returns
- bool
true when the provided
parentis a parent node ofnode, otherwise false.
Type Parameters
TValue type.
IsRoot<T>(ITreeNode<T>)
Checks whether or not the provided node is a root node.
[Pure]
public static bool IsRoot<T>(this ITreeNode<T> node)
Parameters
nodeITreeNode<T>Node to check.
Returns
- bool
true when the node is a root node (does not have a parent node), otherwise false.
Type Parameters
TValue type.
VisitAncestors<T>(ITreeNode<T>)
Creates a new IEnumerable<T> instance that contains all ancestors of the provided node.
[Pure]
public static IEnumerable<ITreeNode<T>> VisitAncestors<T>(this ITreeNode<T> node)
Parameters
nodeITreeNode<T>Source node.
Returns
- IEnumerable<ITreeNode<T>>
New IEnumerable<T> instance.
Type Parameters
TValue type.
VisitDescendants<T>(ITreeNode<T>)
Creates a new IEnumerable<T> instance that contains all descendants of the provided node.
[Pure]
public static IEnumerable<ITreeNode<T>> VisitDescendants<T>(this ITreeNode<T> node)
Parameters
nodeITreeNode<T>Source node.
Returns
- IEnumerable<ITreeNode<T>>
New IEnumerable<T> instance.
Type Parameters
TValue type.
VisitDescendants<T>(ITreeNode<T>, Func<ITreeNode<T>, bool>)
Creates a new IEnumerable<T> instance that contains all descendants of the provided node
with a stopPredicate.
[Pure]
public static IEnumerable<ITreeNode<T>> VisitDescendants<T>(this ITreeNode<T> node, Func<ITreeNode<T>, bool> stopPredicate)
Parameters
nodeITreeNode<T>Source node.
stopPredicateFunc<ITreeNode<T>, bool>Predicate that stops the traversal for the given sub-tree, when it returns true.
Returns
- IEnumerable<ITreeNode<T>>
New IEnumerable<T> instance.
Type Parameters
TValue type.