EasyTree 1.1.0

dotnet add package EasyTree --version 1.1.0
NuGet\Install-Package EasyTree -Version 1.1.0
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="EasyTree" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasyTree --version 1.1.0
#r "nuget: EasyTree, 1.1.0"
#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 EasyTree as a Cake Addin
#addin nuget:?package=EasyTree&version=1.1.0

// Install EasyTree as a Cake Tool
#tool nuget:?package=EasyTree&version=1.1.0

EasyTree

EasyTree is a project to create a base class for tree-like objects in C#. Inheriting from the Node class provides APIs for creating, managing, and navigating a tree.

Usage

Creating a Tree

The basis of the tree is an instance of the Node class in the EasyTree namespace. Every node in the tree can be used to create its own subtree, with corresponding methods and properties.

The Node constructor has two overloads:

new Node();
new Node(Node parent);

You can construct a tree by creating each node and passing in its parent as parameter. The class also features the following parent/child management methods:

// Adds a child node to an existing node
void AddChild(Node child) {...}

// Removes a child node
void RemoveChild(Node child) {...}

// Adds a parent to an existing node
void AddParent(Node parent) {...}

// Removes a parent and makes the node a root
void RemoveParent(Node parent) {...}

Properties

The Node class features the following convenient properties.

// The node's parent
Node Parent { get; }

// The node's root
Node Root { get; }

// The full path from the node back to the root
IReadOnlyList<Node> Path { get; }

// List of the node's children in chronological order (the order you added them)
IReadOnlyList<Node> Children { get; }

// True if the node is a leaf
bool IsLeaf { get; }

// True if the node is a root
bool IsRoot { get; }

Searching your Tree

You can iterate through the descendants of any node by using any of the following methods, which return IEnumerator<Node>.

// Iterate through the tree with root myNode using a depth-first pre-order search
foreach (Node element in myNode.GetPreOrderIterator())
{
    // Insert code
}

// Iterate through the tree with root myNode using a depth-first post-order search
foreach (Node element in myNode.GetPostOrderIterator())
{
    // Insert code
}

// Iterate through the tree with root myNode using a breadth-first level-order search
foreach (Node element in myNode.GetLevelOrderIterator())
{
    // Insert code
}

Other Methods

In addition to the methods above for creating and iterating through a tree, the Node class has a number of methods to make navigating the tree easier.

// Gets a collection of the descendants of the current node.
IReadOnlyCollection<Node> GetDescendants() {...}

// Gets a collection of the tree's leaves, with the current node as root.
IReadOnlyCollection<Node> GetLeaves() {...}

Usage

Creating a custom class

You can either use the Node class directly or inherit from it to create your own custom class of tree-like objects that makes use of the above APIs.

You can find a minimum working example of a custom class here:

using EasyTree;

namespace CustomNameSpace
{
    public class SampleClass : Node
    {
        // Insert custom properties here

        public SampleClass(...) : base()
        {
            // Insert custom constructor here
        }

        public SampleClass(..., SampleClass parent) : base(parent)
        {
            // Insert custom constructor overload here
        }
    }
}

Contributing

Feel free to contribute by creating an issue or submitting a PR.

Author

Kier von Konigslow

License

This project is licensed under the MIT License - see the LICENSE file for details

Product 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.0

    • 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.0 1,768 1/22/2021
1.1.0-alpha 316 12/21/2020
1.0.1-alpha 294 12/9/2020
1.0.0-alpha 215 12/9/2020
0.5.0 570 3/6/2020
0.3.1 461 3/1/2020
0.3.0 476 3/1/2020
0.2.0 452 2/25/2020
0.1.0 458 2/24/2020

Features:
* Improved performance
* Better iterators