In This Article

AstNodeBase Class

Represents an abstract AST (abstract syntax tree) node implementation that is intended to be used as a base class for type-specific AST nodes.

public abstract class AstNodeBase : IAstNode
Inheritance:
object object
Derived:
AccessorBody AccessorDeclaration Argument ArrayReallocateClause Attribute AttributeArgument AttributeSection CatchClause ClassBody CollectionElement CompilationUnit CompilationUnitOption ConstructorBody Designation DocumentationComment ElseIfSection EnumerationBody EventBody Expression ExternalAliasDirective ExternalAliasDirectiveSection FixedSizeBufferDeclarator InterfaceBody LocalFunctionStatementBody MethodBody NamespaceBody NamespaceDeclaration OperatorBody Ordering ParameterDeclaration Pattern PreprocessorDirective PropertyBody QualifiedName QueryOperator RangeVariableDeclaration RangeVariableDeclarator ReturnTypeDeclaration Statement StructureBody SubPattern SwitchExpressionArm SwitchLabel SwitchSection TupleLiteralDeclarator TypeDeclaration TypeMemberDeclaration TypeParameter UsingDirective UsingDirectiveSection VariableDeclarator ArrayInitializerExpression ArrayPattern AssignmentExpression AssignmentPattern AssignmentProperty AwaitExpression BinaryOperatorExpression BlockStatement BreakStatement CallExpression CatchClause ClassBody ClassDeclaration ClassExpression CompilationUnit ConditionalExpression ContinueStatement DebuggerStatement DoStatement ExpressionStatement ForInStatement ForStatement FunctionBody FunctionDeclaration FunctionExpression Identifier IfStatement ImportExpression InstanceExpression LabeledStatement LiteralExpression MemberAccess MethodDefinition ModuleDeclaration ModuleSpecifier ObjectCreationExpression ObjectInitializerExpression ObjectPattern OmittedExpression OmittedPattern ParenthesizedExpression Property RestElement ReturnStatement SequenceExpression SuperExpression SwitchSection SwitchStatement TaggedTemplateExpression ThrowStatement TryStatement UnaryOperatorExpression VariableDeclaration VariableDeclarator WhileStatement WithStatement YieldExpression Argument CaseBlock CompilationUnit ComprehensionClauseBase Decorator Expression IfStatementCondition Parameter Pattern SliceItem Statement TryStatementExceptClause CDataSection Comment CompilationUnit Declaration Element ElementAttribute ElementContent EndTag ProcessingInstruction
Implements:
IAstNode

Constructors

AstNodeBase()

Initializes an instance of the class.

protected AstNodeBase()

Properties

Children

The collection of child AST nodes.

public IEnumerable<IAstNode> Children { get; }

Property Value

IEnumerable<IAstNode>

EndOffset

The end offset of this AST node, if known.

public int? EndOffset { get; set; }

Property Value

int?

HasChildren

Indicates whether the AST node contains any child AST nodes.

public bool HasChildren { get; }

Property Value

bool:

true if the AST node contains any child AST nodes; otherwise, false.

Id

An integer value that identifies the type of AST node, if known.

public virtual int Id { get; }

Property Value

int

Remarks

This class' default implementation always returns 0.

Length

The character length of this AST node, if known.

public int Length { get; }

Property Value

int

Parent

The parent IAstNode of this AST node, if known.

public IAstNode? Parent { get; set; }

Property Value

IAstNode

Root

The root IAstNode of this AST node hierarchy, if known.

public IAstNode Root { get; }

Property Value

IAstNode

Remarks

The root node is found by walking up the Parent tree.

StartOffset

The start offset of this AST node, if known.

public int? StartOffset { get; set; }

Property Value

int?

Value

The string-based value for the AST node.

public virtual string? Value { get; set; }

Property Value

string

Methods

Contains(int)

Returns whether the AST node contains the specified offset.

public bool Contains(int offset)
Parameter Type Description
offset int

The offset to examine.

Returns

bool:

true if the AST node contains the specified offset; otherwise, false.

Remarks

This method returns false if the offset falls on the EndOffset offset since this method indicates if the offset is encompassed by the AST node. This method also returns false if the AST node doesn't have known offsets.

FindChildNode(int)

Searches through the child nodes for a node that contains the specified offset.

public IAstNode? FindChildNode(int offset)
Parameter Type Description
offset int

The offset to check.

Returns

IAstNode:

The child IAstNode that contains the specified offset, if any.

FindDescendantNode(int)

Recursively searches through the descendant nodes for a node that contains the specified offset.

public IAstNode? FindDescendantNode(int offset)
Parameter Type Description
offset int

The offset to check.

Returns

IAstNode:

The descendant IAstNode that contains the specified offset, if any.

GetChildrenEnumerator()

Retrieves an IEnumerator object that can iterate the child IAstNode objects in this node.

protected virtual IEnumerator<IAstNode>? GetChildrenEnumerator()

Returns

IEnumerator<IAstNode>

ToString()

Returns the string representation of this object.

public override string ToString()

Returns

string:

The string representation of this object.

ToTreeString(int)

Outputs the contents of the AST node in tree form.

public string ToTreeString(int indentLevel)
Parameter Type Description
indentLevel int

The indentation level.

Returns

string

Inherited Members

Extension Methods