Class Tree<T>
Represents a tree with data of the specified type stored in the tree nodes.
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public class Tree<T> : Object, ITree<T>, ITree
Type Parameters
Name | Description |
---|---|
T | Type of the data contained in the tree nodes. |
Constructors
Tree(T)
Creates a new tree node with the specified stored data and without any children.
Declaration
public Tree(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | Data to store in the node. |
Tree(T, IEnumerable<ITree<T>>)
Creates a new tree node with the specified stored data and with the specified children.
Declaration
public Tree(T value, IEnumerable<ITree<T>> children)
Parameters
Type | Name | Description |
---|---|---|
T | value | Data stored in the node. |
System.Collections.Generic.IEnumerable<ITree<T>> | children | Child nodes. |
Tree(T, ITree<T>[])
Creates a new tree node with the specified stored data and with the specified children.
Declaration
public Tree(T value, params ITree<T>[] children)
Parameters
Type | Name | Description |
---|---|---|
T | value | Data stored in the node. |
ITree<T>[] | children | Child nodes. |
Properties
Children
Gets the children of the current tree node.
Declaration
public virtual IReadOnlyList<ITree<T>> Children { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<ITree<T>> |
Value
Gets the data stored in the node.
Declaration
public virtual T Value { get; }
Property Value
Type | Description |
---|---|
T |
Methods
Accept(ITreeVisitor<T>)
Dispatches the current tree instance to the tree visitor's Visit method.
Declaration
public ITree<T> Accept(ITreeVisitor<T> visitor)
Parameters
Type | Name | Description |
---|---|---|
ITreeVisitor<T> | visitor | Visitor to accept the tree. |
Returns
Type | Description |
---|---|
ITree<T> | Result of the visit. |
ToString()
Gets a string representation of the current node and its children.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | String representation of the current node. |
ToString(Int32)
Gets a string representation of the current node and its children, using the specified indentation level.
Declaration
public virtual string ToString(int indent)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | indent | Indentation level. Recursive calls to obtain a string representation of child nodes will use an incremented indentation level. |
Returns
Type | Description |
---|---|
System.String | String representation of the current node. |
ToStringFormat()
Gets a format string with placeholders for the children. To be used with String.Format.
Declaration
public virtual string ToStringFormat()
Returns
Type | Description |
---|---|
System.String | Format string that can be used to retrieve a string representation of the current node by supplying string representations of child nodes. |
Update(IEnumerable<ITree<T>>)
Updates the tree with the given children, returning a new immutable tree.
Declaration
public ITree<T> Update(IEnumerable<ITree<T>> children)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ITree<T>> | children | Child nodes for the copy of the current node. |
Returns
Type | Description |
---|---|
ITree<T> | New immutable tree based on the current node, but with the specified child nodes. |
Update(ITree<T>[])
Updates the tree with the given children, returning a new immutable tree.
Declaration
public ITree<T> Update(params ITree<T>[] children)
Parameters
Type | Name | Description |
---|---|---|
ITree<T>[] | children | Child nodes for the copy of the current node. |
Returns
Type | Description |
---|---|
ITree<T> | New immutable tree based on the current node, but with the specified child nodes. |
UpdateCore(IEnumerable<ITree<T>>)
Updates the tree with the given children, returning a new immutable tree.
Declaration
protected virtual ITree<T> UpdateCore(IEnumerable<ITree<T>> children)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ITree<T>> | children | Child nodes for the copy of the current node. |
Returns
Type | Description |
---|---|
ITree<T> | New immutable tree based on the current node, but with the specified child nodes. |
Explicit Interface Implementations
ITree.Accept(ITreeVisitor)
Dispatches the current tree instance to the tree visitor's Visit method.
Declaration
ITree ITree.Accept(ITreeVisitor visitor)
Parameters
Type | Name | Description |
---|---|---|
ITreeVisitor | visitor | Visitor to accept the tree. |
Returns
Type | Description |
---|---|
ITree | Result of the visit. |
ITree.Children
Gets the children of the current tree node.
Declaration
IReadOnlyList<ITree> ITree.Children { get; }
Returns
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<ITree> |
ITree.Update(IEnumerable<ITree>)
Updates the tree with the given children, returning a new immutable tree.
Declaration
ITree ITree.Update(IEnumerable<ITree> children)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ITree> | children | Child nodes for the copy of the current node. |
Returns
Type | Description |
---|---|
ITree | New immutable tree based on the current node, but with the specified child nodes. |
ITree.Value
Gets the data stored in the node.
Declaration
object ITree.Value { get; }
Returns
Type | Description |
---|---|
System.Object |