EasyTree 0.5.0
See the version list below for details.
dotnet add package EasyTree --version 0.5.0
NuGet\Install-Package EasyTree -Version 0.5.0
<PackageReference Include="EasyTree" Version="0.5.0" />
<PackageVersion Include="EasyTree" Version="0.5.0" />
<PackageReference Include="EasyTree" />
paket add EasyTree --version 0.5.0
#r "nuget: EasyTree, 0.5.0"
#:package EasyTree@0.5.0
#addin nuget:?package=EasyTree&version=0.5.0
#tool nuget:?package=EasyTree&version=0.5.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 four overloads:
new Node();
new Node(string id);
new Node(Node parent);
new Node(string id, Node parent);
You can construct a tree by creating each node and passing in its parent as parameter. The class also features the following methods:
// Adds a child node to an existing node
public void AddChild(Node child){...}
// Creates then adds a child node to an existing node, return the child
public Node AddChild(){...}
// Creates then adds a child node to an existing node, return the child
public Node AddChild(string id){...}
// Removes a child node
public void RemoveChild(Node child){...}
// Adds a parent to an existing node
public void AddParent(Node parent){...}
// Creates then adds a parent to an existing node, returns the parent
public Node AddParent(){...}
// Creates then adds a parent to an existing node, returns the parent
public Node AddParent(string id){...}
// Removes a parent and makes the node a root
public void RemoveParent(Node parent){...}
Features
Node objects also feature the following convenient read-only properties:
// The node's parent
public Node Parent
// The node's root
public Node Root
// The full path from the node back to the root
public List<Node> Path
// List of the node's children in chronological order (the order you added them)
public List<Node> Children
// HashSet (unordered) of the node's leaves
public HashSet<Node> Leaves
// HashSet (unordered) of the node's descendants
public HashSet<Node> Descendants
// True if the node is a leaf
public bool IsLeaf
// True if the node is a root
public bool IsRoot
Node objects also allow you to pretty print the tree to the console using the following method:
public void PrintPretty();
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)
{
SampleName = sampleName;
// Insert custom constructor overload here
}
}
}
Iterators
The EasyTree.Iterators namespace provides classes that implement the IEnumerable interface that allow you to search the tree.
// Iterate through the tree using a depth-first pre-order search
foreach (Node element in new PreOrderIterator(yourNode))
{
// Insert code
}
// Iterate through the tree using a depth-first post-order search
foreach (Node element in new PostOrderIterator(yourNode))
{
// Insert code
}
// Iterate through the tree using a breadth-first level-order search
foreach (Node element in new LevelOrderIterator(yourNode))
{
// Insert code
}
Contributing
Feel free to contribute by creating an issue or submitting a PR.
Author
License
This project is licensed under the MIT License - see the LICENSE file for details
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. 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. |
-
.NETStandard 2.0
- NLog (>= 4.6.8)
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:
* Added two new constructor overloads
* Added breadth-first iterator class