Class HasChildrenExtensions
A set of helper functions and extensions for working with IHasChildren implementations
Inherited Members
Namespace: LemonEdge.Utils
Assembly: LemonEdge.Utils.dll
Syntax
public static class HasChildrenExtensions
Methods
ContainsMatchingNode<T>(T, Func<T, bool>)
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 |
Func<T, bool> | match | A function that given a node of type T returns if it matches the filter or not |
Returns
Type | Description |
---|---|
bool | The node, or any of its child nodes (recursively) that match the specified function |
Type Parameters
Name | Description |
---|---|
T | The type of child items |
CopyNode<T>(T, CreateCopiedNode<T>)
Declaration
public static Task<T> CopyNode<T>(this T node, HasChildrenExtensions.CreateCopiedNode<T> createCopiedNode) where T : IHasChildren
Parameters
Type | Name | Description |
---|---|---|
T | node | |
HasChildrenExtensions.CreateCopiedNode<T> | createCopiedNode |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T |
CopyNode<T>(T, T, CreateCopiedNode<T>)
Declaration
public static Task<T> CopyNode<T>(this T node, T copiedParent, HasChildrenExtensions.CreateCopiedNode<T> createCopiedNode) where T : IHasChildren
Parameters
Type | Name | Description |
---|---|---|
T | node | |
T | copiedParent | |
HasChildrenExtensions.CreateCopiedNode<T> | createCopiedNode |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T |
CreateWithMatchingNodesOnly<T>(IEnumerable<T>, Func<T, bool>, Func<T, T, T>)
Creates a new set of T nodes where items and child items only exist if eventually a child item matches the requested type of node
Declaration
public static IEnumerable<T> CreateWithMatchingNodesOnly<T>(this IEnumerable<T> nodes, Func<T, bool> match, Func<T, T, T> createFromOriginal) where T : class, IHasChildren
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | nodes | |
Func<T, bool> | match | |
Func<T, T, T> | createFromOriginal |
Returns
Type | Description |
---|---|
IEnumerable<T> |
Type Parameters
Name | Description |
---|---|
T |
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 |
---|---|
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 |
---|---|
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 |
---|---|
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 |
---|---|
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, bool>)
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 |
Func<T, bool> | 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 |
string | pathSeperator | The string to use to separate items in the path to the root node |
Func<T, string> | nodePathLabel | A function that given a node returns a label for representing it in the path |
Returns
Type | Description |
---|---|
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 |
---|---|
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 |
---|---|
bool | 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 |
---|---|
int | The maximum level deep the child items from this node goes. Returns 0 if there are no child items at all. |