Class HasChildrenExtensions
A set of helper functions and extensions for working with IHasChildren implementations
Inheritance
Inherited Members
Namespace: LemonEdge.Utils
Assembly: Utils.dll
Syntax
public static class HasChildrenExtensions
Methods
ContainsMatchingNode<T>(T, Func<T, Boolean>)
Returns true if this node, or any of its child nodes (recursively) match the specified function
Declaration
public static bool ContainsMatchingNode<T>(this T node, Func<T, bool> match)
where T : class, IHasChildren
Parameters
Type | Name | Description |
---|---|---|
T | node | The node to see if it, or any of its children, match |
System.Func<T, System.Boolean> | match | A function that given a node of type T returns if it matches the filter or not |
Returns
Type | Description |
---|---|
System.Boolean | The node, or any of its child nodes (recursively) that match the specified function |
Type Parameters
Name | Description |
---|---|
T | The type of child items |
GetAllChildren(IHasChildren)
Returns a flat list of all child items in this item and their child items recursively
Declaration
public static IEnumerable<IHasChildren> GetAllChildren(this IHasChildren node)
Parameters
Type | Name | Description |
---|---|---|
IHasChildren | node | The item to return all child items and their child items recursively from |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IHasChildren> | A flat list of all child items in this item and their child items recursively |
GetAllChildren<T>(IHasChildren<T>)
Returns a flat list of all child items in this item and their child items recursively
Declaration
public static IEnumerable<T> GetAllChildren<T>(this IHasChildren<T> node)
where T : IHasChildren<T>
Parameters
Type | Name | Description |
---|---|---|
IHasChildren<T> | node | The item to return all child items and their child items recursively from |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | A flat list of all child items in this item and their child items recursively |
Type Parameters
Name | Description |
---|---|
T | The type of IHasChildren items |
GetLeafChildNodesOnly(IHasChildren)
Returns child items (recursively) from this item that they themselves don't have any child nodes. In other words the leaf items from this tree.
Declaration
public static IEnumerable<IHasChildren> GetLeafChildNodesOnly(this IHasChildren node)
Parameters
Type | Name | Description |
---|---|---|
IHasChildren | node | The item to find all child items (Recursively) from that dont have any child items of their own |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IHasChildren> | A list of child items (recursively) from this item that they themselves don't have any child nodes. In other words the leaf items from this tree. |
GetLeafChildNodesOnly<T>(T)
Returns child items (recursively) from this item that they themselves don't have any child nodes. In other words the leaf items from this tree.
Declaration
public static IEnumerable<T> GetLeafChildNodesOnly<T>(this T node)
where T : IHasChildren
Parameters
Type | Name | Description |
---|---|---|
T | node | The item to find all child items (Recursively) from that dont have any child items of their own |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | A list of child items (recursively) from this item that they themselves don't have any child nodes. In other words the leaf items from this tree. |
Type Parameters
Name | Description |
---|---|
T | The type of IHasChildren items |
GetMatchingNode<T>(T, Func<T, Boolean>)
Returns the first matching node from the node, or any of its child nodes (recursively)
Declaration
public static T GetMatchingNode<T>(this T node, Func<T, bool> match)
where T : class, IHasChildren
Parameters
Type | Name | Description |
---|---|---|
T | node | The node to see if it, or any of its children, match |
System.Func<T, System.Boolean> | match | A function that given a node of type T returns if it matches the filter or not |
Returns
Type | Description |
---|---|
T | The first matching node from the node |
Type Parameters
Name | Description |
---|---|
T | The type of child items |
GetPath<T>(T, String, Func<T, String>)
Given a node returns the root to that node as a path formatted for each node
Declaration
public static string GetPath<T>(this T item, string pathSeperator, Func<T, string> nodePathLabel)
where T : IHasChildren
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to get the path as a string from this node to the root one |
System.String | pathSeperator | The string to use to separate items in the path to the root node |
System.Func<T, System.String> | nodePathLabel | A function that given a node returns a label for representing it in the path |
Returns
Type | Description |
---|---|
System.String | The root to that node as a path formatted for each node |
Type Parameters
Name | Description |
---|---|
T | The type of nodes |
GetRootParent(IHasChildren)
Returns the ultimate root parent of this item. Recursively walks up the tree until it finds the ultimate top level item
Declaration
public static IHasChildren GetRootParent(this IHasChildren node)
Parameters
Type | Name | Description |
---|---|---|
IHasChildren | node | The item to find the ultimate parent of |
Returns
Type | Description |
---|---|
IHasChildren | The ultimate root parent of this item. Recursively walks up the tree until it finds the ultimate top level item |
GetRootParent<T>(T)
Returns the ultimate root parent of this item. Recursively walks up the tree until it finds the ultimate top level item
Declaration
public static T GetRootParent<T>(this T node)
where T : IHasChildren
Parameters
Type | Name | Description |
---|---|---|
T | node | The item to find the ultimate parent of |
Returns
Type | Description |
---|---|
T | The ultimate root parent of this item. Recursively walks up the tree until it finds the ultimate top level item |
Type Parameters
Name | Description |
---|---|
T | The type of IHasChildren items |
GetRootToNode<T>(T)
Returns the set of parent items above this node (including this node) that are traversed in order to reach the top level root node that has no other parent
Declaration
public static IEnumerable<T> GetRootToNode<T>(this T item)
where T : IHasChildren
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to start creating a root to the top node from |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | The set of parent items above this node (including this node) that are traversed in order to reach the top level root node that has no other parent |
Type Parameters
Name | Description |
---|---|
T | The type of nodes |
HasChildren(IHasChildren)
Returns true if the specified item has any child items
Declaration
public static bool HasChildren(this IHasChildren node)
Parameters
Type | Name | Description |
---|---|---|
IHasChildren | node | The specified item to check if it has any child items |
Returns
Type | Description |
---|---|
System.Boolean | True if the specified item has any child items |
MaxTreeDepth(IHasChildren)
Returns the maximum length of child items deep this tree goes from the specified node
Declaration
public static int MaxTreeDepth(this IHasChildren node)
Parameters
Type | Name | Description |
---|---|---|
IHasChildren | node | The node to find the maximum length of child items before the deepest leaf node |
Returns
Type | Description |
---|---|
System.Int32 | The maximum level deep the child items from this node goes. Returns 0 if there are no child items at all. |