Table of Contents

Class AstNode

Namespace
ICSharpCode.Decompiler.CSharp.Syntax
Assembly
ICSharpCode.Decompiler.dll
public abstract class AstNode : AbstractAnnotatable, IAnnotatable, IFreezable, INode, ICloneable
Inheritance
AstNode
Implements
Derived
Inherited Members
Extension Methods

Constructors

AstNode()

protected AstNode()

Fields

AstNodeFlagsUsedBits

protected const int AstNodeFlagsUsedBits = 10

Field Value

int

Null

public static readonly AstNode Null

Field Value

AstNode

flags

protected uint flags

Field Value

uint

Properties

Ancestors

Gets the ancestors of this node (excluding this node itself)

public IEnumerable<AstNode> Ancestors { get; }

Property Value

IEnumerable<AstNode>

AncestorsAndSelf

Gets the ancestors of this node (including this node itself)

public IEnumerable<AstNode> AncestorsAndSelf { get; }

Property Value

IEnumerable<AstNode>

Children

public IEnumerable<AstNode> Children { get; }

Property Value

IEnumerable<AstNode>

Descendants

Gets all descendants of this node (excluding this node itself) in pre-order.

public IEnumerable<AstNode> Descendants { get; }

Property Value

IEnumerable<AstNode>

DescendantsAndSelf

Gets all descendants of this node (including this node itself) in pre-order.

public IEnumerable<AstNode> DescendantsAndSelf { get; }

Property Value

IEnumerable<AstNode>

EndLocation

public virtual TextLocation EndLocation { get; }

Property Value

TextLocation

FirstChild

public AstNode? FirstChild { get; }

Property Value

AstNode

HasChildren

public bool HasChildren { get; }

Property Value

bool

IsFrozen

Gets if this instance is frozen. Frozen instances are immutable and thus thread-safe.

public bool IsFrozen { get; }

Property Value

bool

IsNull

public virtual bool IsNull { get; }

Property Value

bool

LastChild

public AstNode? LastChild { get; }

Property Value

AstNode

NextSibling

public AstNode? NextSibling { get; }

Property Value

AstNode

NodeType

public abstract NodeType NodeType { get; }

Property Value

NodeType

Parent

public AstNode? Parent { get; }

Property Value

AstNode

PrevSibling

public AstNode? PrevSibling { get; }

Property Value

AstNode

Role

public Role Role { get; set; }

Property Value

Role

StartLocation

public virtual TextLocation StartLocation { get; }

Property Value

TextLocation

Methods

AcceptVisitor(IAstVisitor)

public abstract void AcceptVisitor(IAstVisitor visitor)

Parameters

visitor IAstVisitor

AcceptVisitor<T>(IAstVisitor<T>)

public abstract T AcceptVisitor<T>(IAstVisitor<T> visitor)

Parameters

visitor IAstVisitor<T>

Returns

T

Type Parameters

T

AcceptVisitor<T, S>(IAstVisitor<T, S>, T)

public abstract S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)

Parameters

visitor IAstVisitor<T, S>
data T

Returns

S

Type Parameters

T
S

AddAnnotation(object)

public override void AddAnnotation(object annotation)

Parameters

annotation object

AddChildWithExistingRole(AstNode?)

public void AddChildWithExistingRole(AstNode? child)

Parameters

child AstNode

AddChild<T>(T, Role<T>)

public void AddChild<T>(T child, Role<T> role) where T : AstNode

Parameters

child T
role Role<T>

Type Parameters

T

Clone()

Clones the whole subtree starting at this AST node.

public AstNode Clone()

Returns

AstNode

Remarks

Annotations are copied over to the new nodes; and any annotations implementing ICloneable will be cloned.

Contains(TextLocation)

Returns true, if the given coordinates are in the node.

public bool Contains(TextLocation location)

Parameters

location TextLocation

Returns

bool

True, if location is between StartLocation and EndLocation (exclusive); otherwise, false.

Contains(int, int)

Returns true, if the given coordinates (line, column) are in the node.

public bool Contains(int line, int column)

Parameters

line int
column int

Returns

bool

True, if the given coordinates are between StartLocation and EndLocation (exclusive); otherwise, false.

DescendantNodes(Func<AstNode, bool>?)

public IEnumerable<AstNode> DescendantNodes(Func<AstNode, bool>? descendIntoChildren = null)

Parameters

descendIntoChildren Func<AstNode, bool>

Returns

IEnumerable<AstNode>

DescendantNodesAndSelf(Func<AstNode, bool>?)

public IEnumerable<AstNode> DescendantNodesAndSelf(Func<AstNode, bool>? descendIntoChildren = null)

Parameters

descendIntoChildren Func<AstNode, bool>

Returns

IEnumerable<AstNode>

DoMatch(AstNode?, Match)

protected abstract bool DoMatch(AstNode? other, Match match)

Parameters

other AstNode
match Match

Returns

bool

Freeze()

Freezes this instance.

public void Freeze()

GetAdjacentNodeAt(TextLocation, Predicate<AstNode>?)

Gets the node specified by pred at location. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End inclusive)

public AstNode? GetAdjacentNodeAt(TextLocation location, Predicate<AstNode>? pred = null)

Parameters

location TextLocation
pred Predicate<AstNode>

Returns

AstNode

GetAdjacentNodeAt(int, int, Predicate<AstNode>?)

Gets the node specified by pred at the location line, column. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End inclusive)

public AstNode? GetAdjacentNodeAt(int line, int column, Predicate<AstNode>? pred = null)

Parameters

line int
column int
pred Predicate<AstNode>

Returns

AstNode

GetAdjacentNodeAt<T>(TextLocation)

Gets the node specified by T at location. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End inclusive)

public T? GetAdjacentNodeAt<T>(TextLocation location) where T : AstNode

Parameters

location TextLocation

Returns

T

Type Parameters

T

GetAdjacentNodeAt<T>(int, int)

Gets the node specified by T at the location line, column. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End inclusive)

public T? GetAdjacentNodeAt<T>(int line, int column) where T : AstNode

Parameters

line int
column int

Returns

T

Type Parameters

T

GetCSharpNodeBefore(AstNode)

public AstNode? GetCSharpNodeBefore(AstNode node)

Parameters

node AstNode

Returns

AstNode

GetChildByRole<T>(Role<T>)

Gets the first child with the specified role. Returns the role's null object if the child is not found.

public T GetChildByRole<T>(Role<T> role) where T : AstNode?

Parameters

role Role<T>

Returns

T

Type Parameters

T

GetChildrenByRole<T>(Role<T>)

public AstNodeCollection<T> GetChildrenByRole<T>(Role<T> role) where T : AstNode

Parameters

role Role<T>

Returns

AstNodeCollection<T>

Type Parameters

T

GetNextNode()

public AstNode? GetNextNode()

Returns

AstNode

GetNextNode(Func<AstNode, bool>)

Gets the next node which fullfills a given predicate

public AstNode? GetNextNode(Func<AstNode, bool> pred)

Parameters

pred Func<AstNode, bool>

The predicate.

Returns

AstNode

The next node.

GetNextSibling(Func<AstNode, bool>)

Gets the next sibling which fullfills a given predicate

public AstNode? GetNextSibling(Func<AstNode, bool> pred)

Parameters

pred Func<AstNode, bool>

The predicate.

Returns

AstNode

The next node.

GetNodeAt(TextLocation, Predicate<AstNode>?)

Gets the node specified by pred at location. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End exclusive)

public AstNode? GetNodeAt(TextLocation location, Predicate<AstNode>? pred = null)

Parameters

location TextLocation
pred Predicate<AstNode>

Returns

AstNode

GetNodeAt(int, int, Predicate<AstNode>?)

Gets the node specified by T at the location line, column. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End exclusive)

public AstNode? GetNodeAt(int line, int column, Predicate<AstNode>? pred = null)

Parameters

line int
column int
pred Predicate<AstNode>

Returns

AstNode

GetNodeAt<T>(TextLocation)

Gets the node specified by T at location. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End exclusive)

public T? GetNodeAt<T>(TextLocation location) where T : AstNode

Parameters

location TextLocation

Returns

T

Type Parameters

T

GetNodeAt<T>(int, int)

Gets the node specified by T at the location line, column. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End exclusive)

public T? GetNodeAt<T>(int line, int column) where T : AstNode

Parameters

line int
column int

Returns

T

Type Parameters

T

GetNodeContaining(TextLocation, TextLocation)

Gets the node that fully contains the range from startLocation to endLocation.

public AstNode GetNodeContaining(TextLocation startLocation, TextLocation endLocation)

Parameters

startLocation TextLocation
endLocation TextLocation

Returns

AstNode

GetNodesBetween(TextLocation, TextLocation)

Returns the root nodes of all subtrees that are fully contained between start and end (inclusive).

public IEnumerable<AstNode> GetNodesBetween(TextLocation start, TextLocation end)

Parameters

start TextLocation
end TextLocation

Returns

IEnumerable<AstNode>

GetNodesBetween(int, int, int, int)

Returns the root nodes of all subtrees that are fully contained in the specified region.

public IEnumerable<AstNode> GetNodesBetween(int startLine, int startColumn, int endLine, int endColumn)

Parameters

startLine int
startColumn int
endLine int
endColumn int

Returns

IEnumerable<AstNode>

GetParent(Func<AstNode, bool>?)

public AstNode? GetParent(Func<AstNode, bool>? pred)

Parameters

pred Func<AstNode, bool>

Returns

AstNode

GetParent<T>()

public T? GetParent<T>() where T : AstNode

Returns

T

Type Parameters

T

GetPrevNode()

public AstNode? GetPrevNode()

Returns

AstNode

GetPrevNode(Func<AstNode, bool>)

Gets the previous node which fullfills a given predicate

public AstNode? GetPrevNode(Func<AstNode, bool> pred)

Parameters

pred Func<AstNode, bool>

The predicate.

Returns

AstNode

The next node.

GetPrevSibling(Func<AstNode, bool>)

Gets the next sibling which fullfills a given predicate

public AstNode? GetPrevSibling(Func<AstNode, bool> pred)

Parameters

pred Func<AstNode, bool>

The predicate.

Returns

AstNode

The next node.

InsertChildAfter<T>(AstNode?, T, Role<T>)

public void InsertChildAfter<T>(AstNode? prevSibling, T child, Role<T> role) where T : AstNode

Parameters

prevSibling AstNode
child T
role Role<T>

Type Parameters

T

InsertChildBefore<T>(AstNode?, T, Role<T>)

public void InsertChildBefore<T>(AstNode? nextSibling, T child, Role<T> role) where T : AstNode

Parameters

nextSibling AstNode
child T
role Role<T>

Type Parameters

T

IsInside(TextLocation)

Returns true, if the given coordinates are in the node.

public bool IsInside(TextLocation location)

Parameters

location TextLocation

Returns

bool

True, if location is between StartLocation and EndLocation (inclusive); otherwise, false.

IsInside(int, int)

Returns true, if the given coordinates (line, column) are in the node.

public bool IsInside(int line, int column)

Parameters

line int
column int

Returns

bool

True, if the given coordinates are between StartLocation and EndLocation (inclusive); otherwise, false.

MatchString(string?, string?)

protected static bool MatchString(string? pattern, string? text)

Parameters

pattern string
text string

Returns

bool

Remove()

Removes this node from its parent.

public void Remove()

ReplaceWith(AstNode?)

Replaces this node with the new node.

public void ReplaceWith(AstNode? newNode)

Parameters

newNode AstNode

ReplaceWith(Func<AstNode, AstNode?>)

public AstNode? ReplaceWith(Func<AstNode, AstNode?> replaceFunction)

Parameters

replaceFunction Func<AstNode, AstNode>

Returns

AstNode

SetChildByRole<T>(Role<T>, T)

protected void SetChildByRole<T>(Role<T> role, T newChild) where T : AstNode

Parameters

role Role<T>
newChild T

Type Parameters

T

ThrowIfFrozen()

protected void ThrowIfFrozen()

ToString()

public override sealed string ToString()

Returns

string

ToString(CSharpFormattingOptions?)

Gets the node as formatted C# output.

public virtual string ToString(CSharpFormattingOptions? formattingOptions)

Parameters

formattingOptions CSharpFormattingOptions

Formatting options.

Returns

string

Operators

implicit operator AstNode?(Pattern?)

public static implicit operator AstNode?(Pattern? pattern)

Parameters

pattern Pattern

Returns

AstNode