Class TreeNode<T>
Class representing a node of a tree.
Inheritance
Inherited Members
Namespace:Extend
Assembly:Extend.dll
Syntax
public class TreeNode<T> : ITreeNode<T>, IDisposable, IEnumerable<ITreeNode<T>>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The type of the value of the node. |
Constructors
| Improve this Doc View SourceTreeNode()
Creates a new instance of the TreeNode<T> class.
Declaration
public TreeNode()
TreeNode(T, ITreeNode<T>)
Creates a new instance of the TreeNode<T> class.
Declaration
public TreeNode(T value, ITreeNode<T> parent)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value of the node. |
ITreeNode<T><T> | parent | The parent of the node. |
TreeNode(T, ITreeNode<T>, ITreeNodeCollection<T>)
Creates a new instance of the TreeNode<T> class.
Declaration
public TreeNode(T value, ITreeNode<T> parent = null, ITreeNodeCollection<T> children = null)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value of the node. |
ITreeNode<T><T> | parent | The parent of the node. |
ITreeNodeCollection<T><T> | children | The children of the node. |
TreeNode(T, ITreeNodeCollection<T>)
Creates a new instance of the TreeNode<T> class.
Declaration
public TreeNode(T value, ITreeNodeCollection<T> children)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value of the node. |
ITreeNodeCollection<T><T> | children | The children of the node. |
TreeNode(ITreeNode<T>)
Creates a new instance of the TreeNode<T> class.
Declaration
public TreeNode(ITreeNode<T> parent)
Parameters
Type | Name | Description |
---|---|---|
ITreeNode<T><T> | parent | The parent of the node. |
TreeNode(ITreeNodeCollection<T>)
Creates a new instance of the TreeNode<T> class.
Declaration
public TreeNode(ITreeNodeCollection<T> children)
Parameters
Type | Name | Description |
---|---|---|
ITreeNodeCollection<T><T> | children | The children of the node. |
Properties
| Improve this Doc View SourceAncestors
Gets an enumeration of all tree nodes which are above the current node in the tree.
Declaration
public IEnumerable<ITreeNode<T>> Ancestors { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><ITreeNode<T><T>> | An enumeration of all tree nodes which are above the current node in the tree. |
AncestorsTraversalDirection
Gets or sets the ancestors traversal direction.
Declaration
public TreeTraversalDirection AncestorsTraversalDirection { get; set; }
Property Value
Type | Description |
---|---|
TreeTraversalDirection | The ancestors traversal direction. |
Implements
| Improve this Doc View SourceChildren
Gets or sets the children of the node.
Declaration
public ITreeNodeCollection<T> Children { get; set; }
Property Value
Type | Description |
---|---|
ITreeNodeCollection<T><T> | The children of the node. |
Implements
| Improve this Doc View SourceDepth
Gets the depth of the node.
Declaration
public int Depth { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The depth of the node. |
Implements
| Improve this Doc View SourceDescendants
Gets an enumeration of all tree nodes which are below the current node in the tree.
Declaration
public IEnumerable<ITreeNode<T>> Descendants { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><ITreeNode<T><T>> | An enumeration of all tree nodes which are below the current node in the tree. |
Implements
| Improve this Doc View SourceDescendantsTraversalDirection
Gets or sets the descendants traversal direction.
Declaration
public TreeTraversalDirection DescendantsTraversalDirection { get; set; }
Property Value
Type | Description |
---|---|
TreeTraversalDirection | The descendants traversal direction. |
Implements
| Improve this Doc View SourceDisposeTraversalDirection
Gets or sets the dispose traversal direction.
Declaration
public TreeTraversalDirection DisposeTraversalDirection { get; set; }
Property Value
Type | Description |
---|---|
TreeTraversalDirection | The dispose traversal direction. |
Implements
| Improve this Doc View SourceHasChildren
Gets a value indicating whether the node has any children or not.
Declaration
public bool HasChildren { get; }
Property Value
Type | Description |
---|---|
System.Boolean | A value indicating whether the node has any children or not. |
Implements
| Improve this Doc View SourceHasParent
Gets a value indicating whether the node has a parent or not.
Declaration
public bool HasParent { get; }
Property Value
Type | Description |
---|---|
System.Boolean | A value indicating whether the node has a parent or not. |
Implements
| Improve this Doc View SourceParent
Gets or sets the parent of the node.
Declaration
public ITreeNode<T> Parent { get; set; }
Property Value
Type | Description |
---|---|
ITreeNode<T><T> | The parent of the node. |
Implements
Remarks
Detaches the node from it's old parent and attaches it to it's new parent.
Root
Gets the root of the tree.
Declaration
public ITreeNode<T> Root { get; }
Property Value
Type | Description |
---|---|
ITreeNode<T><T> | The root of the tree. |
Implements
| Improve this Doc View SourceSearchTraversalDirection
Gets or sets the search traversal direction.
Declaration
public TreeTraversalDirection SearchTraversalDirection { get; set; }
Property Value
Type | Description |
---|---|
TreeTraversalDirection | The search traversal direction. |
Implements
| Improve this Doc View SourceTraversalDirection
Gets or sets the traversal direction used to enumerate the nodes.
Declaration
public TreeTraversalDirection TraversalDirection { get; set; }
Property Value
Type | Description |
---|---|
TreeTraversalDirection | The traversal direction used to enumerate the nodes. |
Implements
| Improve this Doc View SourceValue
Gets or sets the value of the node.
Declaration
public T Value { get; set; }
Property Value
Type | Description |
---|---|
T | The value of the node. |
Implements
Methods
| Improve this Doc View SourceAdd(T)
Adds the given value as child to the node.
Declaration
public ITreeNode<T> Add(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to add. |
Returns
Type | Description |
---|---|
ITreeNode<T><T> | Returns the added node. |
Implements
| Improve this Doc View SourceAdd(ITreeNode<T>)
Adds the given node as child to the node, if it is not already a child of the node.
Declaration
public ITreeNode<T> Add(ITreeNode<T> node)
Parameters
Type | Name | Description |
---|---|---|
ITreeNode<T><T> | node | The node to add. |
Returns
Type | Description |
---|---|
ITreeNode<T><T> | Returns the added node. |
Implements
| Improve this Doc View SourceDispose()
Release all resources hold by the node.
Declaration
public void Dispose()
Implements
Dispose(Boolean)
Releases the managed and unmanaged resource hold by the node.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | A value of true to release managed resources, false to release unmanaged resources. |
Finalize()
Destructs the tree node..
Declaration
protected void Finalize()
FindNode(T)
Gets the nodes with the given value.
Declaration
public IEnumerable<ITreeNode<T>> FindNode(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to search. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><ITreeNode<T><T>> | Returns the nodes with the given value. |
Implements
| Improve this Doc View SourceFindNode(Func<ITreeNode<T>, Boolean>)
Gets the nodes which matches the given predicate.
Declaration
public virtual IEnumerable<ITreeNode<T>> FindNode(Func<ITreeNode<T>, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, TResult><ITreeNode<T><T>, System.Boolean> | predicate | The predicate. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><ITreeNode<T><T>> | Returns the nodes which matches the given predicate. |
Implements
Remarks
Starts the search at the current tree node and traverses down the tree (Direction based on
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | predicate can not be null. |
FindValue(Func<ITreeNode<T>, Boolean>)
Gets the values which matches the given predicate.
Declaration
public virtual IEnumerable<T> FindValue(Func<ITreeNode<T>, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, TResult><ITreeNode<T><T>, System.Boolean> | predicate | The predicate. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><T> | Returns the values which matches the given predicate. |
Implements
Remarks
Starts the search at the current tree node and traverses down the tree (Direction based on
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | predicate can not be null. |
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<ITreeNode<T>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T><ITreeNode<T><T>> | A System.Collections.Generic.IEnumerator<T> that can be used to iterate through the collection. |
Implements
SetAllDirections(TreeTraversalDirection)
Sets all directions (DisposeTraversalDirection, SearchTraversalDirection,
AncestorsTraversalDirection, DescendantsTraversalDirection).
Declaration
public void SetAllDirections(TreeTraversalDirection direction)
Parameters
Type | Name | Description |
---|---|---|
TreeTraversalDirection | direction | The new direction. |
Implements
| Improve this Doc View SourceSetParent(ITreeNode<T>, Boolean, Boolean)
Sets the parent of the tree node.
Declaration
public void SetParent(ITreeNode<T> parent, bool attacheToNewParent = true, bool detachFromOldParent = true)
Parameters
Type | Name | Description |
---|---|---|
ITreeNode<T><T> | parent | The new parent. |
System.Boolean | attacheToNewParent | A value determining whether the node should add it self to the children of the new parent or not. |
System.Boolean | detachFromOldParent | A value indicating whether the node should detach itself from it's old parent or not. |
Implements
| Improve this Doc View SourceToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string that represents the current object. |
Overrides
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | A System.Collections.IEnumerator that can be used to iterate through the collection. |