Flatten<TDocument>(IEnumerable<TDocument>, bool, string) Method
Flattens a tree structure.
Namespace
Statiq.Common
Containing Type
IDocumentEnumerableExtensions

Syntax

public static DocumentList<TDocument> Flatten<TDocument>(this IEnumerable<TDocument> documents, bool removeTreePlaceholders, string childrenKey = "Children") 
    where TDocument : IDocument

Remarks

This extension will either get all descendants of all documents from a given metadata key (Children by default) or all descendants from all metadata if a null key is specified. The result also includes the initial documents in both cases. The documents will be returned in no particular order and only distinct documents will be returned (I.e., if a document exists as a child of more than one parent, it will only appear once in the result set).

Type Parameters

Name Description
TDocument

Parameters

Name Type Description
documents IEnumerable<TDocument> The documents to flatten.
removeTreePlaceholders bool true to filter out documents with the TreePlaceholder metadata.
childrenKey string The metadata key that contains the children or null to flatten documents in all metadata keys.

Return Value

Type Description
DocumentList<TDocument> The flattened documents.