Hierarchy 1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Hierarchy --version 1.0.1
NuGet\Install-Package Hierarchy -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hierarchy" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hierarchy --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Hierarchy, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hierarchy as a Cake Addin #addin nuget:?package=Hierarchy&version=1.0.1 // Install Hierarchy as a Cake Tool #tool nuget:?package=Hierarchy&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Hierarchy
A .Net Standard library that can be used for hierarchical data
Getting Started
- Install the package from NuGet
- Transform any flat hierarchical list into a hierarchical tree structure by using the ToHierarchy extension method
- Use other extension methods to perform operations on the new Hierarchy list.
Example
private class Example
{
public int Id { get; set; }
public int ParentId { get; set; }
public string Name { get; set; } = "";
}
private List<Example> flatList = new()
{
new() { Id = 1, ParentId = 0, Name = "Top Level 1" },
new() { Id = 2, ParentId = 1, Name = "Top Level 1.1" },
new() { Id = 3, ParentId = 1, Name = "Top Level 1.2" },
new() { Id = 12, ParentId = 3, Name = "Top Level 1.2.1" },
new() { Id = 10, ParentId = 1, Name = "Top Level 1.3" },
new() { Id = 11, ParentId = 1, Name = "Top Level 1.4" },
new() { Id = 4, ParentId = 0, Name = "Top Level 2" },
new() { Id = 5, ParentId = 4, Name = "Top Level 2.1" },
new() { Id = 6, ParentId = 4, Name = "Top Level 2.2" },
new() { Id = 7, ParentId = 4, Name = "Top Level 2.3" },
new() { Id = 13, ParentId = 7, Name = "Top Level 2.3.1" },
new() { Id = 14, ParentId = 13, Name = "Top Level 2.3.1.1" },
new() { Id = 8, ParentId = 4, Name = "Top Level 2.4" },
new() { Id = 9, ParentId = 0, Name = "Top Level 3" },
};
private void TestTraversalMethod()
{
// We convert the flat list to a hierarchy
var hierarchyList = flatList.ToHierarchy(t => t.Id, t => t.ParentId);
// We search through all nodes in the hierarchy for the one with Id = 7
var node = hierarchyList.AllNodes().FirstOrDefault(n => n.Data?.Id == 7); // Returns the node with Id 7
// We get all other nodes that are at the same level as this node
var siblingNodes = node.SiblingNodes(); // Returns the following nodes { 5, 6, 8 } (NOTE: This excludes the node being used)
// We get all descendant nodes of this node
var childNodes = node.DescendantNodes(); // Returns the following nodes { 13, 14 }
// We get all ancestor nodes of this node
var parentNodes = node.AncestorNodes(); // Returns the following nodes { 4 }
// We get all leaf nodes (descendant nodes that do not have childen) of this node
var leafNodes = node.LeafNodes(); // Returns the following node { 14 }
// We get the top level node of this branch (the highest level ancestor)
var rootNode = node.RootNode(); // Returns the following node { 4 }
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.1 | 2,231 | 4/17/2022 |
1.1.0 | 402 | 4/16/2022 |
1.0.2 | 390 | 4/15/2022 |
1.0.1 | 401 | 4/15/2022 |
1.0.0-alpha | 137 | 4/14/2022 |
initial release