Tree

Energy.Base.Tree, Energy.Base.TreeNode and Energy.Base.TreeNodeList provide a simple generic tree structure.

TreeNode

A node can hold a typed value, an optional associated object, and a list of child nodes.

Energy.Base.TreeNode<string> root = new Energy.Base.TreeNode<string>("Root");

Energy.Base.TreeNode<string> child1 = root.Children.Add("Child 1");
Energy.Base.TreeNode<string> child2 = root.Children.Add("Child 2");

child1.Children.Add("Grandchild 1");
child1.Children.Add("Grandchild 2");

Console.WriteLine(root.ToString("+ "));

Tree

Energy.Base.Tree is a root node that does not render its own value, only its children.

Energy.Base.Tree<string> tree = new Energy.Base.Tree<string>();

tree.Children.Add("a");
Energy.Base.TreeNode<string> b = tree.Children.Add("b");
b.Children.Add("d");
b.Children.Add("e");
Energy.Base.TreeNode<string> c = tree.Children.Add("c");
c.Children.Add("f");

Console.WriteLine(tree.ToString("+ "));

Properties and methods

Member Description
TreeNode<T>.Value Node value.
TreeNode<T>.Object Optional associated object.
TreeNode<T>.Children Child node list.
TreeNode<T>.Parent Parent node.
TreeNode<T>.Root Top-level node.
TreeNode<T>.Depth Depth of the node.
TreeNode<T>.ToString(string indent) Render the tree with the given indent string.
TreeNodeList<T>.Add(T value) Add a value and return the new node.
TreeNodeList<T>.Add(TreeNode<T> item) Add an existing node.