Hierarchy Class
Creates trees of HierarchyNode<T> from nested objects, from rows with a parent identifier, or from paths.
public static class HierarchyMethods
| Name | Description |
|---|---|
| FromPaths<T>(IEnumerable<T>, Func<T, string>, Func<T, double>?, char) | Creates a tree from rows that give their path, such as src/app/main.cs. The intermediate nodes the paths imply are created, with the default value of T as their data. |
| FromTree<T>(T, Func<T, IEnumerable<T>?>, Func<T, string?>?, Func<T, double>?) | Creates a tree from nested objects. |
| Stratify<T>(IEnumerable<T>, Func<T, string>, Func<T, string?>, Func<T, double>?) | Creates a tree from rows that give their identifier and the identifier of their parent. |
FromPaths<T>(IEnumerable<T>, Func<T, string>, Func<T, double>?, char)
Hierarchy.csCreates a tree from rows that give their path, such as src/app/main.cs. The intermediate nodes the paths imply are created, with the default value of T as their data.
public static HierarchyNode<T?> FromPaths<T>(IEnumerable<T> rows, Func<T, string> path, Func<T, double>? value = null, char separator = '/')Type parameters
T- The type of the rows.
Parameters
rowsIEnumerable<T>- The rows.
pathFunc<T, string>- The path of a row.
valueFunc<T, double>?- The own value of a row, to compute the values of the nodes; or
nullto leave them at zero. separatorchar- The separator of the segments of the paths. The default is
/.
Returns
HierarchyNode<T?> The root node: a node with an empty name, whose children are the first segments of the paths.
FromTree<T>(T, Func<T, IEnumerable<T>?>, Func<T, string?>?, Func<T, double>?)
Hierarchy.csCreates a tree from nested objects.
public static HierarchyNode<T> FromTree<T>(T root, Func<T, IEnumerable<T>?> children, Func<T, string?>? name = null, Func<T, double>? value = null)Type parameters
T- The type of the objects.
Parameters
rootT- The root object.
childrenFunc<T, IEnumerable<T>?>- The children of an object, or
nullfor none. nameFunc<T, string?>?- The name of an object, or
nullto useObject.ToString. valueFunc<T, double>?- The own value of an object, to compute the values of the nodes with
HierarchyNode<T>.Sum; ornullto leave them at zero.
Returns
HierarchyNode<T> The root node.
Stratify<T>(IEnumerable<T>, Func<T, string>, Func<T, string?>, Func<T, double>?)
Hierarchy.csCreates a tree from rows that give their identifier and the identifier of their parent.
public static HierarchyNode<T> Stratify<T>(IEnumerable<T> rows, Func<T, string> id, Func<T, string?> parentId, Func<T, double>? value = null)Type parameters
T- The type of the rows.
Parameters
rowsIEnumerable<T>- The rows. Exactly one of them, the root, has no parent.
idFunc<T, string>- The identifier of a row, which is also the name of its node.
parentIdFunc<T, string?>- The identifier of the parent of a row, or
nullor empty for the root. valueFunc<T, double>?- The own value of a row, to compute the values of the nodes; or
nullto leave them at zero.
Returns
HierarchyNode<T> The root node.
Exceptions
ArgumentException- There is no root or several roots, an identifier is duplicated, a parent does not exist, or there is a cycle.