Partilhar via


SyntaxNode Class

Definition

Represents a non-terminal node in the syntax tree. This is the language agnostic equivalent of CSharpSyntaxNode and VisualBasicSyntaxNode.

public ref class SyntaxNode abstract
[System.Diagnostics.DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public abstract class SyntaxNode
[<System.Diagnostics.DebuggerDisplay("{GetDebuggerDisplay(), nq}")>]
type SyntaxNode = class
Public MustInherit Class SyntaxNode
Inheritance
SyntaxNode
Derived
Attributes

Properties

ContainsAnnotations

Determines whether this node or any sub node, token or trivia has annotations.

ContainsDiagnostics

Determines whether this node or any of its descendant nodes, tokens or trivia have any diagnostics on them.

ContainsDirectives

Determines whether this node has any descendant preprocessor directives.

ContainsSkippedText

Determines whether this node has any descendant skipped text.

FullSpan

The absolute span of this node in characters, including its leading and trailing trivia.

HasLeadingTrivia

Determines whether this node has any leading trivia.

HasStructuredTrivia

Determines whether a descendant trivia of this node is structured.

HasTrailingTrivia

Determines whether this node has any trailing trivia.

IsMissing

Determines whether the node represents a language construct that was actually parsed from the source code. Missing nodes are generated by the parser in error scenarios to represent constructs that should have been present in the source code in order to compile successfully but were actually missing.

IsStructuredTrivia

Determines whether this node represents a structured trivia.

KindText
Language

The language name that this node is syntax of.

Parent

The node that contains this node in its ChildNodes() collection.

ParentTrivia
RawKind

An integer representing the language specific kind of this node.

Span

The absolute span of this node in characters, not including its leading and trailing trivia.

SpanStart

Same as accessing Start on Span.

SyntaxTree

Returns SyntaxTree that owns the node.

SyntaxTreeCore

Returns SyntaxTree that owns the node. If the node does not belong to a tree then one will be generated.

Methods

Ancestors(Boolean)

Gets a list of ancestor nodes

AncestorsAndSelf(Boolean)

Gets a list of ancestor nodes (including this node)

ChildNodes()

Gets a list of the child nodes in prefix document order.

ChildNodesAndTokens()

The list of child nodes and tokens of this node, where each element is a SyntaxNodeOrToken instance.

ChildThatContainsPosition(Int32)
ChildTokens()

Gets a list of the direct child tokens of this node.

Contains(SyntaxNode)

Determines if the specified node is a descendant of this node. Returns true for current node.

ContainsDirective(Int32)

Returns true if this node contains any directives (e.g. #if, #nullable, etc.) within it with a matching kind.

CopyAnnotationsTo<T>(T)

Copies all SyntaxAnnotations, if any, from this SyntaxNode instance and attaches them to a new instance based on node.

DescendantNodes(Func<SyntaxNode,Boolean>, Boolean)

Gets a list of descendant nodes in prefix document order.

DescendantNodes(TextSpan, Func<SyntaxNode,Boolean>, Boolean)

Gets a list of descendant nodes in prefix document order.

DescendantNodesAndSelf(Func<SyntaxNode,Boolean>, Boolean)

Gets a list of descendant nodes (including this node) in prefix document order.

DescendantNodesAndSelf(TextSpan, Func<SyntaxNode,Boolean>, Boolean)

Gets a list of descendant nodes (including this node) in prefix document order.

DescendantNodesAndTokens(Func<SyntaxNode,Boolean>, Boolean)

Gets a list of descendant nodes and tokens in prefix document order.

DescendantNodesAndTokens(TextSpan, Func<SyntaxNode,Boolean>, Boolean)

Gets a list of the descendant nodes and tokens in prefix document order.

DescendantNodesAndTokensAndSelf(Func<SyntaxNode,Boolean>, Boolean)

Gets a list of descendant nodes and tokens (including this node) in prefix document order.

DescendantNodesAndTokensAndSelf(TextSpan, Func<SyntaxNode,Boolean>, Boolean)

Gets a list of the descendant nodes and tokens (including this node) in prefix document order.

DescendantTokens(Func<SyntaxNode,Boolean>, Boolean)

Gets a list of all the tokens in the span of this node.

DescendantTokens(TextSpan, Func<SyntaxNode,Boolean>, Boolean)

Gets a list of all the tokens in the full span of this node.

DescendantTrivia(Func<SyntaxNode,Boolean>, Boolean)

Get a list of all the trivia associated with the descendant nodes and tokens.

DescendantTrivia(TextSpan, Func<SyntaxNode,Boolean>, Boolean)

Get a list of all the trivia associated with the descendant nodes and tokens.

EquivalentToCore(SyntaxNode)

Determine if this node is structurally equivalent to another.

FindNode(TextSpan, Boolean, Boolean)

Finds the node with the smallest FullSpan that contains span. getInnermostNodeForTie is used to determine the behavior in case of a tie (i.e. a node having the same span as its parent). If getInnermostNodeForTie is true, then it returns lowest descending node encompassing the given span. Otherwise, it returns the outermost node encompassing the given span.

FindToken(Int32, Boolean)

Finds a descendant token of this node whose span includes the supplied position.

FindTokenCore(Int32, Boolean)

Finds a descendant token of this node whose span includes the supplied position.

FindTokenCore(Int32, Func<SyntaxTrivia,Boolean>)

Finds a descendant token of this node whose span includes the supplied position.

FindTrivia(Int32, Boolean)

Finds a descendant trivia of this node whose span includes the supplied position.

FindTrivia(Int32, Func<SyntaxTrivia,Boolean>)

Finds a descendant trivia of this node at the specified position, where the position is within the span of the node.

FindTriviaCore(Int32, Boolean)

Finds a descendant trivia of this node whose span includes the supplied position.

FirstAncestorOrSelf<TNode,TArg>(Func<TNode,TArg,Boolean>, TArg, Boolean)

Gets the first node of type TNode that matches the predicate.

FirstAncestorOrSelf<TNode>(Func<TNode,Boolean>, Boolean)

Gets the first node of type TNode that matches the predicate.

GetAnnotatedNodes(String)

Gets all nodes with the specified annotation kind.

GetAnnotatedNodes(SyntaxAnnotation)

Gets all nodes with the specified annotation.

GetAnnotatedNodesAndTokens(String)

Gets all nodes and tokens with an annotation of the specified annotation kind.

GetAnnotatedNodesAndTokens(String[])

Gets all nodes and tokens with an annotation of the specified annotation kinds.

GetAnnotatedNodesAndTokens(SyntaxAnnotation)

Gets all nodes and tokens with the specified annotation.

GetAnnotatedTokens(String)

Gets all tokens with the specified annotation kind.

GetAnnotatedTokens(SyntaxAnnotation)

Gets all tokens with the specified annotation.

GetAnnotatedTrivia(String)

Gets all trivia with an annotation of the specified annotation kind.

GetAnnotatedTrivia(String[])

Gets all trivia with an annotation of the specified annotation kinds.

GetAnnotatedTrivia(SyntaxAnnotation)

Gets all trivia with the specified annotation.

GetAnnotations(IEnumerable<String>)

Gets all the annotations with the specified annotation kinds.

GetAnnotations(String)

Gets all the annotations with the specified annotation kind.

GetDiagnostics()

Gets a list of all the diagnostics in the sub tree that has this node as its root. This method does not filter diagnostics based on #pragmas and compiler options like nowarn, warnaserror etc.

GetFirstToken(Boolean, Boolean, Boolean, Boolean)

Gets the first token of the tree rooted by this node. Skips zero-width tokens.

GetLastToken(Boolean, Boolean, Boolean, Boolean)

Gets the last token of the tree rooted by this node. Skips zero-width tokens.

GetLeadingTrivia()

The list of trivia that appears before this node in the source code and are attached to a token that is a descendant of this node.

GetLocation()
GetRed<T>(T, Int32)
GetRedAtZero<T>(T)
GetReference()

Gets a SyntaxReference for this syntax node. CommonSyntaxReferences can be used to regain access to a syntax node without keeping the entire tree and source text in memory.

GetText(Encoding, SourceHashAlgorithm)

Gets the full text of this node as a new SourceText instance.

GetTrailingTrivia()

The list of trivia that appears after this node in the source code and are attached to a token that is a descendant of this node.

HasAnnotation(SyntaxAnnotation)

Determines whether this node has the specific annotation.

HasAnnotations(IEnumerable<String>)

Determines whether this node has any annotations with any of the specific annotation kinds.

HasAnnotations(String)

Determines whether this node has any annotations with the specific annotation kind.

InsertNodesInListCore(SyntaxNode, IEnumerable<SyntaxNode>, Boolean)
InsertTokensInListCore(SyntaxToken, IEnumerable<SyntaxToken>, Boolean)
InsertTriviaInListCore(SyntaxTrivia, IEnumerable<SyntaxTrivia>, Boolean)
IsEquivalentTo(SyntaxNode, Boolean)

Determines if two nodes are the same, disregarding trivia differences.

IsEquivalentTo(SyntaxNode)

Determine whether this node is structurally equivalent to another.

IsEquivalentToCore(SyntaxNode, Boolean)

Determines if two nodes are the same, disregarding trivia differences.

IsIncrementallyIdenticalTo(SyntaxNode)

Returns true if these two nodes are considered "incrementally identical". An incrementally identical node occurs when a SyntaxTree is incrementally parsed using WithChangedText(SourceText) and the incremental parser is able to take the node from the original tree and use it in its entirety in the new tree. In this case, the ToFullString() of each node will be the same, though they could have different parents, and may occur at different positions in their respective trees. If two nodes are incrementally identical, all children of each node will be incrementally identical as well.

IsPartOfStructuredTrivia()

Determines whether this node is a descendant of a structured trivia.

NormalizeWhitespaceCore(String, String, Boolean)
RemoveNodesCore(IEnumerable<SyntaxNode>, SyntaxRemoveOptions)

Creates a new tree of nodes with the specified node removed.

ReplaceCore<TNode>(IEnumerable<TNode>, Func<TNode,TNode,SyntaxNode>, IEnumerable<SyntaxToken>, Func<SyntaxToken,SyntaxToken,SyntaxToken>, IEnumerable<SyntaxTrivia>, Func<SyntaxTrivia,SyntaxTrivia,SyntaxTrivia>)

Creates a new tree of nodes with the specified nodes, tokens or trivia replaced.

ReplaceNodeInListCore(SyntaxNode, IEnumerable<SyntaxNode>)
ReplaceTokenInListCore(SyntaxToken, IEnumerable<SyntaxToken>)
ReplaceTriviaInListCore(SyntaxTrivia, IEnumerable<SyntaxTrivia>)
SerializeTo(Stream, CancellationToken)
Obsolete.
Obsolete.

Serializes the node to the given stream. Leaves the stream open for further writes.

ToFullString()

Returns full string representation of this node including its leading and trailing trivia.

ToString()

Returns the string representation of this node, not including its leading and trailing trivia.

WriteTo(TextWriter)

Writes the full text of this node to the specified TextWriter.

Extension Methods

GetFirstDirective(SyntaxNode, Func<DirectiveTriviaSyntax,Boolean>)

Gets the first directive of the tree rooted by this node.

GetLastDirective(SyntaxNode, Func<DirectiveTriviaSyntax,Boolean>)

Gets the last directive of the tree rooted by this node.

Kind(SyntaxNode)

Returns SyntaxKind for SyntaxNode from RawKind property.

TryGetInferredMemberName(SyntaxNode)

Given an initializer expression infer the name of anonymous property or tuple element. Returns null if unsuccessful

ContainsDirective(SyntaxNode, SyntaxKind)

Returns true if this node contains any directives (e.g. #if, #nullable, etc.) within it with a matching kind.

IsKind(SyntaxNode, SyntaxKind)

Determines if SyntaxNode is of a specified kind.

GetCurrentNode<TNode>(SyntaxNode, TNode)

Gets the node within the subtree corresponding to the original tracked node. Use TrackNodes to start tracking nodes.

GetCurrentNodes<TNode>(SyntaxNode, TNode)

Gets the nodes within the subtree corresponding to the original tracked node. Use TrackNodes to start tracking nodes.

GetCurrentNodes<TNode>(SyntaxNode, IEnumerable<TNode>)

Gets the nodes within the subtree corresponding to the original tracked nodes. Use TrackNodes to start tracking nodes.

TryGetInferredMemberName(SyntaxNode)

Given an initializer expression infer the name of anonymous property or tuple element. Returns Nothing if unsuccessful

GetDirectives(SyntaxNode, Func<DirectiveTriviaSyntax,Boolean>)

Gets the DirectiveTriviaSyntax items for a specified SyntaxNode with optional filtering.

GetFirstDirective(SyntaxNode, Func<DirectiveTriviaSyntax,Boolean>)

Gets the first DirectiveTriviaSyntax item for a specified SyntaxNode.

GetLastDirective(SyntaxNode, Func<DirectiveTriviaSyntax,Boolean>)

Gets the last DirectiveTriviaSyntax item for a specified SyntaxNode.

Kind(SyntaxNode)

Returns SyntaxKind for SyntaxNode from RawKind property.

ContainsDirective(SyntaxNode, SyntaxKind)

Returns true if this node contains any directives (e.g. #if, #nullable, etc.) within it with a matching kind.

IsKind(SyntaxNode, SyntaxKind)

Determines if SyntaxNode is of a specified kind.

Applies to