Open sandboxFocus

Method SelectManyRecursive

SelectManyRecursive<T>(IEnumerable<T>, Func<T, IEnumerable<T>?>, bool)

Selects the closure of a graph by recursively gathering children for each root item. This is typically used to select all descendants of tree nodes.

Declaration
public static List<T> SelectManyRecursive<T>(this IEnumerable<T> roots, Func<T, IEnumerable<T>?> getChildren, bool includeRoot = false) where T : class
Parameters
Type Name Description
IEnumerable<T> roots

The initial collection of root items.

Func<T, IEnumerable<T>> getChildren

A function that returns the set of all child nodes connected to a given node.

bool includeRoot

A value indicating whether the root items themselves should be included in the result set.

Returns
Type Description
List<T>

A list containing the closure of the graph starting from roots.

Type Parameters
Name Description
T

The type of items in the graph.