MrKWatkins.Ast Help

Children<TNode> Class

Definition

Collection of child nodes for a Node<TNode>.

public sealed class Children<TNode> : IList<TNode>, ICollection<TNode>, IEnumerable<TNode>, IEnumerable where TNode : Node<TNode>

Type Parameters

Name

Description

TNode

The base node type for the collection.

Properties

Name

Description

Capacity

Current capacity of the collection. The capacity is the size of the internal array used to hold items. When set, the internal array of the list is reallocated to the given capacity.

Count

The number of nodes in the collection.

First

Gets the first child in the collection.

FirstOrNull

Gets the first child in the collection or null if the collection is empty.

Item[Int32]

Gets or sets the node at the specified index. Parents will be updated accordingly on set.

Last

Gets the last child in the collection.

LastOrNull

Gets the last child in the collection or null if the collection is empty.

UnsafeFirst

Gets the first child in the collection without array bounds checks. For high performance scenarios. WARNING: Do not use unless you are certain of the number of children!

UnsafeLast

Gets the last child in the collection without array bounds checks. For high performance scenarios. WARNING: Do not use unless you are certain of the number of children!

Methods

Name

Description

Add(TNode)

Adds a node to the collection and assigns its Parent property.

Add(IEnumerable<TNode>)

Adds nodes to the collection and assigns their Parent properties.

Add(ICollection<TNode>)

Adds nodes to the collection and assigns their Parent properties.

Add(TNode[])

Adds nodes to the collection and assigns their Parent properties.

Clear()

Removes all nodes from the collection and resets their Parent properties to null.

Contains(TNode)

Determines if the specified node is in the collection or not.

ExceptOfType<TChild>()

Lazily enumerates over all nodes in this collection not of the specified type.

FirstIfTypeOrDefault<TChild>(TChild)

Returns the first node in the collection if it is of the specified type or a specified default if the collection is empty or the first node is a different type.

FirstOfType<TChild>()

Returns the first node in the collection of the specified type or throws otherwise.

FirstOfTypeOrDefault<TChild>(TChild)

Returns the first node in the collection of the specified type or a specified default if it doesn't contain any nodes of the specified type.

GetEnumerator()

IndexOf(TNode)

Gets the index of the specified node in this collection.

Insert(Int32, TNode)

Inserts a node into the collection at the specified position and assigns its Parent property.

LastIfTypeOrDefault<TChild>(TChild)

Returns the last node in the collection if it is of the specified type or a specified default if the collection is empty or the last node is a different type.

LastOfType<TChild>()

Returns the last node in the collection of the specified type or throws otherwise.

LastOfTypeOrDefault<TChild>(TChild)

Returns the last node in the collection of the specified type or a specified default if it doesn't contain any nodes of the specified type.

Move(TNode)

Moves a node from it's current parent (if it has one) and into this collection.

Move(IEnumerable<TNode>)

Moves nodes from their current parents (if they have one) into this collection.

Move(TNode[])

Moves nodes from their current parents (if they have one) into this collection.

OfType<TChild>()

Lazily enumerates over all nodes in this collection of the specified type.

Remove(TNode)

Tries to remove a node from the collection and reset its Parent property to null.

RemoveAt(Int32)

Removes the node at the specified position from the collection and reset its Parent property to null.

Replace(TNode, TNode)

Replaces a node in the collection with another node. The replacement will be removed from its parent and the node being replaced will have it's parent removed.

SingleOfType<TChild>()

Returns the only node in the collection of the specified type. Throws if there is not exactly one node in the collection of the specified type.

SingleOfTypeOrDefault<TChild>(TChild)

Returns the only node in the collection of the specified type. Returns the specified default if there are no nodes in the collection of the specified type. Throws if there are multiple nodes in the collection of the specified type.

UnsafeGet(Int32)

Gets the child at the specified index in the collection without array bounds checks. For high performance scenarios. WARNING: Do not use unless you are certain of the number of children!

Last modified: 22 November 2024