SyntaxNode Class

Base class used to define a TOML Syntax tree.

public abstract class SyntaxNode : SyntaxNodeBase
Inheritance
SyntaxNodeBase SyntaxNode

Constructors

NameDescription
SyntaxNode(SyntaxKind)Initializes a new instance of the SyntaxNode class.

SyntaxNode(SyntaxKind)

SyntaxNode.cs

Initializes a new instance of the SyntaxNode class.

protected SyntaxNode(SyntaxKind kind)

Parameters

kind SyntaxKind
The kind of syntax node.

Properties

NameDescription
ChildrenCountGets the number of children.
KindGets the type of node.
LeadingTriviaGets the leading trivia attached to this node. Might be null if no leading trivias.
TrailingTriviaGets the trailing trivia attached to this node. Might be null if no trailing trivias.

ChildrenCount

Gets the number of children.

public abstract int ChildrenCount { get; }

Property value

int

Gets the type of node.

public SyntaxKind Kind { get; }

Property value

SyntaxKind

LeadingTrivia

SyntaxNode.cs

Gets the leading trivia attached to this node. Might be null if no leading trivias.

public List<SyntaxTrivia>? LeadingTrivia { get; set; }

Property value

List<SyntaxTrivia>?

TrailingTrivia

SyntaxNode.cs

Gets the trailing trivia attached to this node. Might be null if no trailing trivias.

public List<SyntaxTrivia>? TrailingTrivia { get; set; }

Property value

List<SyntaxTrivia>?

Methods

NameDescription
GetChild(int)Gets a child at the specified index.
GetChildImpl(int)Gets a child at the specified index.
ParentToThis<TSyntaxNode>(TSyntaxNode?, TSyntaxNode?)Helper method to deparent/parent a node to this instance.
ParentToThis<TSyntaxNode>(TSyntaxNode?, TSyntaxNode?, TokenKind)Helper method to deparent/parent a SyntaxToken to this instance with an expected kind of token.
ParentToThis<TSyntaxNode>(TSyntaxNode?, TSyntaxNode?, TokenKind, TokenKind)Helper method to deparent/parent a SyntaxToken to this instance with an expected kind of token.
ParentToThis<TSyntaxNode, TExpected>(TSyntaxNode?, TSyntaxNode?, bool, TExpected)Helper method to deparent/parent a SyntaxToken to this instance with an expected kind of token condition.
ToString()Returns a string that represents the current object.
WriteTo(TextWriter)Writes this node to a textual TOML representation

GetChild(int)

SyntaxNode.cs

Gets a child at the specified index.

public SyntaxNode? GetChild(int index)

Parameters

index int
Index of the child

Returns

SyntaxNode? A child at the specified index

GetChildImpl(int)

Gets a child at the specified index.

protected abstract SyntaxNode? GetChildImpl(int index)

Parameters

index int
Index of the child

Returns

SyntaxNode? A child at the specified index

Remarks

The index is safe to use

ParentToThis overloads

ParentToThis<TSyntaxNode>(TSyntaxNode?, TSyntaxNode?)

SyntaxNode.cs

Helper method to deparent/parent a node to this instance.

protected void ParentToThis<TSyntaxNode>(ref TSyntaxNode? set, TSyntaxNode? node) where TSyntaxNode : SyntaxNode
Type parameters
TSyntaxNode
Type of the node
Parameters
set TSyntaxNode?
The previous child node parented to this instance
node TSyntaxNode?
The new child node to parent to this instance

ParentToThis<TSyntaxNode>(TSyntaxNode?, TSyntaxNode?, TokenKind)

SyntaxNode.cs

Helper method to deparent/parent a SyntaxToken to this instance with an expected kind of token.

protected void ParentToThis<TSyntaxNode>(ref TSyntaxNode? set, TSyntaxNode? node, TokenKind expectedKind) where TSyntaxNode : SyntaxToken
Type parameters
TSyntaxNode
Type of the node
Parameters
set TSyntaxNode?
The previous child node parented to this instance
node TSyntaxNode?
The new child node to parent to this instance
expectedKind TokenKind
The expected kind of token

ParentToThis<TSyntaxNode>(TSyntaxNode?, TSyntaxNode?, TokenKind, TokenKind)

SyntaxNode.cs

Helper method to deparent/parent a SyntaxToken to this instance with an expected kind of token.

protected void ParentToThis<TSyntaxNode>(ref TSyntaxNode? set, TSyntaxNode? node, TokenKind expectedKind1, TokenKind expectedKind2) where TSyntaxNode : SyntaxToken
Type parameters
TSyntaxNode
Type of the node
Parameters
set TSyntaxNode?
The previous child node parented to this instance
node TSyntaxNode?
The new child node to parent to this instance
expectedKind1 TokenKind
The expected kind of token (option1)
expectedKind2 TokenKind
The expected kind of token (option2)

ParentToThis<TSyntaxNode, TExpected>(TSyntaxNode?, TSyntaxNode?, bool, TExpected)

SyntaxNode.cs

Helper method to deparent/parent a SyntaxToken to this instance with an expected kind of token condition.

protected void ParentToThis<TSyntaxNode, TExpected>(ref TSyntaxNode? set, TSyntaxNode? node, bool expectedKindSuccess, TExpected expectedMessage) where TSyntaxNode : SyntaxToken
Type parameters
TSyntaxNode
Type of the node
TExpected
The type of message
Parameters
set TSyntaxNode?
The previous child node parented to this instance
node TSyntaxNode?
The new child node to parent to this instance
expectedKindSuccess bool
true if kind is matching, false otherwise
expectedMessage TExpected
The message to display if the kind is not matching

ToString()

SyntaxNode.cs

Returns a string that represents the current object.

public override string ToString()

Returns

string A string that represents the current object.

WriteTo(TextWriter)

SyntaxNode.cs

Writes this node to a textual TOML representation

public void WriteTo(TextWriter writer)

Parameters

writer TextWriter
A writer to receive the TOML output