EasyTree 1.0.0-alpha

This is a prerelease version of EasyTree.
There is a newer version of this package available.
See the version list below for details.
dotnet add package EasyTree --version 1.0.0-alpha
                    
NuGet\Install-Package EasyTree -Version 1.0.0-alpha
                    
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.0.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasyTree" Version="1.0.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="EasyTree" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EasyTree --version 1.0.0-alpha
                    
#r "nuget: EasyTree, 1.0.0-alpha"
                    
#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.
#:package EasyTree@1.0.0-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EasyTree&version=1.0.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=EasyTree&version=1.0.0-alpha&prerelease
                    
Install as a Cake Tool

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
public void AddChild(Node child){...}

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

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

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

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
}

Features

Node objects also feature the following convenient properties:

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

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

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

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

// HashSet (unordered) of the node's leaves
public HashSet<Node> Leaves { get; }

// HashSet (unordered) of the node's descendants
public HashSet<Node> Descendants { get; }

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

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

You can inherit from this class to create your own tree-like class.

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.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 3,147 1/22/2021
1.1.0-alpha 426 12/21/2020
1.0.1-alpha 405 12/9/2020
1.0.0-alpha 323 12/9/2020
0.5.0 695 3/6/2020
0.3.1 587 3/1/2020
0.3.0 592 3/1/2020
0.2.0 575 2/25/2020
0.1.0 587 2/24/2020

Features:
* Simplified how iterators are requested
* Made some properties read-only