Class HierarchyExtensions
Extension methods for a hierarchical structure based on IHierarchy<T>.
Inheritance
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class HierarchyExtensions
Methods
| Improve this DocAncestorsAndSelf<T>(IHierarchy<T>)
Gets all ancestors (parent, grandparent, etc.) and self of the specified node
in the hierarchical structure.
Declaration
public static IEnumerable<IHierarchy<T>> AncestorsAndSelf<T>(this IHierarchy<T> node)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node that the hierarchical structure represents. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IHierarchy<T>> | An System.Collections.Generic.IEnumerable<T> sequence equal to ancestors and self of the specified |
Type Parameters
Name | Description |
---|---|
T | The type of the instance represented by the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
DescendantsAndSelf<T>(IHierarchy<T>)
Gets all descendants (children, grandchildren, etc.) anf self of the current node
in the hierarchical structure.
Declaration
public static IEnumerable<IHierarchy<T>> DescendantsAndSelf<T>(this IHierarchy<T> node)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node that the hierarchical structure represents. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IHierarchy<T>> | An System.Collections.Generic.IEnumerable<T> sequence equal to the descendants and self of the specified |
Type Parameters
Name | Description |
---|---|
T | The type of the instance represented by the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Find<T>(IHierarchy<T>, Func<IHierarchy<T>, Boolean>)
Retrieves all nodes that match the conditions defined by the function delegate match
.
Declaration
public static IEnumerable<IHierarchy<T>> Find<T>(this IHierarchy<T> node, Func<IHierarchy<T>, bool> match)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node to search. |
System.Func<IHierarchy<T>, System.Boolean> | match | The function delegate that defines the conditions of the nodes to search for. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IHierarchy<T>> | An System.Collections.Generic.IEnumerable<T> sequence containing all nodes that match the conditions defined by the specified predicate, if found. |
Type Parameters
Name | Description |
---|---|
T | The type of the instance that this node represents. |
FindFirst<T>(IHierarchy<T>, Func<IHierarchy<T>, Boolean>)
Returns the first node that match the conditions defined by the function delegate match
, or a default value if no node is found.
Declaration
public static IHierarchy<T> FindFirst<T>(this IHierarchy<T> node, Func<IHierarchy<T>, bool> match)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node to search. |
System.Func<IHierarchy<T>, System.Boolean> | match | The function delegate that defines the conditions of the nodes to search for. |
Returns
Type | Description |
---|---|
IHierarchy<T> | An IHierarchy<T> node that match the conditions defined by the function delegate |
Type Parameters
Name | Description |
---|---|
T | The type of the instance that this node represents. |
FindFirstInstance<T>(IHierarchy<T>, Func<IHierarchy<T>, Boolean>)
Returns the first node instance that match the conditions defined by the function delegate match
, or a default value if no node is found.
Declaration
public static T FindFirstInstance<T>(this IHierarchy<T> node, Func<IHierarchy<T>, bool> match)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node to search. |
System.Func<IHierarchy<T>, System.Boolean> | match | The function delegate that defines the conditions of the nodes to search for. |
Returns
Type | Description |
---|---|
T | An Instance that match the conditions defined by the function delegate |
Type Parameters
Name | Description |
---|---|
T | The type of the instance that this node represents. |
FindInstance<T>(IHierarchy<T>, Func<IHierarchy<T>, Boolean>)
Retrieves all node instances that match the conditions defined by the function delegate match
.
Declaration
public static IEnumerable<T> FindInstance<T>(this IHierarchy<T> node, Func<IHierarchy<T>, bool> match)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node to search. |
System.Func<IHierarchy<T>, System.Boolean> | match | The function delegate that defines the conditions of the nodes to search for. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | An System.Collections.Generic.IEnumerable<T> sequence containing all node instances that match the conditions defined by the specified predicate, if found. |
Type Parameters
Name | Description |
---|---|
T | The type of the instance that this node represents. |
FindSingle<T>(IHierarchy<T>, Func<IHierarchy<T>, Boolean>)
Returns the only node that match the conditions defined by the function delegate match
, or a default value if no node is found; this method throws an exception if more than one node is found.
Declaration
public static IHierarchy<T> FindSingle<T>(this IHierarchy<T> node, Func<IHierarchy<T>, bool> match)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node to search. |
System.Func<IHierarchy<T>, System.Boolean> | match | The function delegate that defines the conditions of the nodes to search for. |
Returns
Type | Description |
---|---|
IHierarchy<T> | An IHierarchy<T> node that match the conditions defined by the function delegate |
Type Parameters
Name | Description |
---|---|
T | The type of the instance that this node represents. |
FindSingleInstance<T>(IHierarchy<T>, Func<IHierarchy<T>, Boolean>)
Returns the only node that match the conditions defined by the function delegate match
, or a default value if no node instance is found; this method throws an exception if more than one node is found.
Declaration
public static T FindSingleInstance<T>(this IHierarchy<T> node, Func<IHierarchy<T>, bool> match)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node to search. |
System.Func<IHierarchy<T>, System.Boolean> | match | The function delegate that defines the conditions of the nodes to search for. |
Returns
Type | Description |
---|---|
T | An Instance node that match the conditions defined by the function delegate |
Type Parameters
Name | Description |
---|---|
T | The type of the instance that this node represents. |
FlattenAll<T>(IHierarchy<T>)
Flattens the entirety of a hierarchical structure representation into an System.Collections.Generic.IEnumerable<T> sequence of nodes.
Declaration
public static IEnumerable<IHierarchy<T>> FlattenAll<T>(this IHierarchy<T> node)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node from which the flattening will begin. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IHierarchy<T>> | An System.Collections.Generic.IEnumerable<T> sequence of IHierarchy<T> all nodes represented by the hierarchical structure. |
Type Parameters
Name | Description |
---|---|
T | The type of the instance represented by the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
NodeAt<T>(IHierarchy<T>, Int32)
Returns the node at the specified index of a hierarchical structure.
Declaration
public static IHierarchy<T> NodeAt<T>(this IHierarchy<T> node, int index)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node from which the flattening will begin. |
System.Int32 | index | The zero-based index at which a node should be retrieved in the hierarchical structure. |
Returns
Type | Description |
---|---|
IHierarchy<T> | The node at the specified |
Type Parameters
Name | Description |
---|---|
T | The type of the instance represented by the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentOutOfRangeException |
|
Replace<T>(IHierarchy<T>, Action<IHierarchy<T>, T>)
Replace the instance of the node
with a replacer
delegate.
Declaration
public static void Replace<T>(this IHierarchy<T> node, Action<IHierarchy<T>, T> replacer)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node to replace with a new instance. |
System.Action<IHierarchy<T>, T> | replacer | The delegate that will replace the wrapped instance of the |
Type Parameters
Name | Description |
---|---|
T | The type of the instance that this node represents. |
ReplaceAll<T>(IEnumerable<IHierarchy<T>>, Action<IHierarchy<T>, T>)
Replace all instances of the nodes
with a replacer
delegate.
Declaration
public static void ReplaceAll<T>(this IEnumerable<IHierarchy<T>> nodes, Action<IHierarchy<T>, T> replacer)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<IHierarchy<T>> | nodes | The sequence of nodes to replace with a new instance. |
System.Action<IHierarchy<T>, T> | replacer | The delegate that will replace all wrapped instances of the |
Type Parameters
Name | Description |
---|---|
T | The type of the instance that these nodes represents. |
Root<T>(IHierarchy<T>)
Returns the root node of the specified node
in the hierarchical structure.
Declaration
public static IHierarchy<T> Root<T>(this IHierarchy<T> node)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node that the hierarchical structure represents. |
Returns
Type | Description |
---|---|
IHierarchy<T> | An IHierarchy<T> node that represents the root of the specified |
Type Parameters
Name | Description |
---|---|
T | The type of the instance represented by the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
SiblingsAndSelf<T>(IHierarchy<T>)
Gets all siblings and self after the current node
in the hierarchical structure.
Declaration
public static IEnumerable<IHierarchy<T>> SiblingsAndSelf<T>(this IHierarchy<T> node)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node that the hierarchical structure represents. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IHierarchy<T>> | An System.Collections.Generic.IEnumerable<T> sequence equal to the siblings and self of the specified |
Type Parameters
Name | Description |
---|---|
T | The type of the instance represented by the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
SiblingsAndSelfAt<T>(IHierarchy<T>, Int32)
Gets all siblings and self after the current node
in the hierarchical structure.
Declaration
public static IEnumerable<IHierarchy<T>> SiblingsAndSelfAt<T>(this IHierarchy<T> node, int depth)
Parameters
Type | Name | Description |
---|---|---|
IHierarchy<T> | node | The node that the hierarchical structure represents. |
System.Int32 | depth | The depth in the hierarchical structure from where to locate the siblings and self nodes. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IHierarchy<T>> | An System.Collections.Generic.IEnumerable<T> sequence equal to the siblings and self of the specified |
Type Parameters
Name | Description |
---|---|
T | The type of the instance represented by the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentOutOfRangeException |
|