AdvantageCMS.Core.Common.BaseClasses Namespace
Advantage CSP

HierarchyExtensions..::..CreateHierarchyList<(Of <(<'TItem, TId>)>)> Method

Creates the hierarchy list.

Namespace:  AdvantageCSP.Core.HierarchicalList
Assembly:  AdvantageCMS.Core (in AdvantageCMS.Core.dll)

Syntax


public static List<IHierarchicalListItem<TItem>> CreateHierarchyList<TItem, TId>(
	this IEnumerable<TItem> flatList,
	Func<TItem, TId> idSelector,
	Func<TItem, TId> parentIdSelector
)

Type Parameters

TItem
The type of the t item.
TId
The type of the t identifier.

Parameters

flatList
Type: IEnumerable<(Of <(<'TItem>)>)>
The flat list.
idSelector
Type: Func<(Of <(<'TItem, TId>)>)>
The identifier selector.
parentIdSelector
Type: Func<(Of <(<'TItem, TId>)>)>
The parent identifier selector.

Return Value

List<IHierarchicalListItem<TItem>>.

Examples


Example of retrieving Navigations setting the parent/child items

C#
private void BuildMenu()
{
var ds1= GetNavigations(eNavigationSelector.VisibleInMenu).CreateHierarchyList(t => t.ID , t => t.ParentID);
// Loop through top level navs
foreach (var ds in ds1)
BuildNavItem(ds, 0);
}
private void BuildNavItem(IHierarchicalListItem<Navigation> node, int depth = 0)
{
// Recursively traverse children
foreach (var child in node.Children)
BuildNavItem(child, depth + 1);
}