Delen via


SyntaxNodeOrToken Struct

Definition

A wrapper for either a syntax node (SyntaxNode) or a syntax token (SyntaxToken).

public value class SyntaxNodeOrToken : IEquatable<Microsoft::CodeAnalysis::SyntaxNodeOrToken>
[System.Diagnostics.DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public readonly struct SyntaxNodeOrToken : IEquatable<Microsoft.CodeAnalysis.SyntaxNodeOrToken>
[<System.Diagnostics.DebuggerDisplay("{GetDebuggerDisplay(), nq}")>]
type SyntaxNodeOrToken = struct
Public Structure SyntaxNodeOrToken
Implements IEquatable(Of SyntaxNodeOrToken)
Inheritance
SyntaxNodeOrToken
Attributes
Implements

Remarks

Note that we do not store the token directly, we just store enough information to reconstruct it. This allows us to reuse nodeOrToken as a token's parent.

Properties

ContainsAnnotations

Determines whether this node or token (or any sub node, token or trivia) as annotations.

ContainsDiagnostics

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

ContainsDirectives

Determines whether the underlying node or token has any descendant preprocessor directives.

FullSpan

The absolute span of the underlying node or token in characters, including its leading and trailing trivia.

HasLeadingTrivia

Determines whether the underlying node or token has any leading trivia.

HasTrailingTrivia

Determines whether the underlying node or token has any trailing trivia.

IsMissing

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

IsNode

Determines whether this SyntaxNodeOrToken is wrapping a node.

IsToken

Determines whether this SyntaxNodeOrToken is wrapping a token.

Language

The language name that this node or token is syntax of.

Parent

The node that contains the underlying node or token in its Children collection.

RawKind

An integer representing the language specific kind of the underlying node or token.

Span

The absolute span of the underlying node or token in characters, not including its leading and trailing trivia.

SpanStart

Same as accessing Start on Span.

SyntaxTree

SyntaxTree which contains current SyntaxNodeOrToken.

Methods

AsNode()

Returns the underlying node if this SyntaxNodeOrToken is wrapping a node.

AsToken()

Returns the underlying token if this SyntaxNodeOrToken is wrapping a token.

ChildNodesAndTokens()

The list of child nodes and tokens of the underlying node or token.

Equals(Object)

Determines whether the supplied SyntaxNodeOrToken is equal to this SyntaxNodeOrToken.

Equals(SyntaxNodeOrToken)

Determines whether the supplied SyntaxNodeOrToken is equal to this SyntaxNodeOrToken.

GetAnnotations(IEnumerable<String>)

Gets all annotations of the specified annotation kind.

GetAnnotations(String)

Gets all annotations of the specified annotation kind.

GetDiagnostics()

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

GetFirstChildIndexSpanningPosition(SyntaxNode, Int32)
GetHashCode()

Serves as hash function for SyntaxNodeOrToken.

GetLeadingTrivia()

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

GetLocation()

Get the location of this node or token.

GetNextSibling()
GetPreviousSibling()
GetTrailingTrivia()

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

HasAnnotation(SyntaxAnnotation)

Determines if this node or token has the specific annotation.

HasAnnotations(IEnumerable<String>)

Determines whether this node or token has annotations of the specified kind.

HasAnnotations(String)

Determines whether this node or token has annotations of the specified kind.

IsEquivalentTo(SyntaxNodeOrToken)

Determines if the two nodes or tokens are equivalent.

IsIncrementallyIdenticalTo(SyntaxNodeOrToken)

See IsIncrementallyIdenticalTo(SyntaxNode) and IsIncrementallyIdenticalTo(SyntaxToken).

ToFullString()

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

ToString()

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

WithAdditionalAnnotations(IEnumerable<SyntaxAnnotation>)

Creates a new node or token identical to this one with the specified annotations.

WithAdditionalAnnotations(SyntaxAnnotation[])

Creates a new node or token identical to this one with the specified annotations.

WithLeadingTrivia(IEnumerable<SyntaxTrivia>)
WithLeadingTrivia(SyntaxTrivia[])
WithoutAnnotations(IEnumerable<SyntaxAnnotation>)

Creates a new node or token identical to this one without the specified annotations.

WithoutAnnotations(String)

Creates a new node or token identical to this one without annotations of the specified kind.

WithoutAnnotations(SyntaxAnnotation[])

Creates a new node or token identical to this one without the specified annotations.

WithTrailingTrivia(IEnumerable<SyntaxTrivia>)
WithTrailingTrivia(SyntaxTrivia[])
WriteTo(TextWriter)

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

Operators

Equality(SyntaxNodeOrToken, SyntaxNodeOrToken)

Determines whether two SyntaxNodeOrTokens are equal.

Explicit(SyntaxNodeOrToken to SyntaxNode)

Returns the underlying node wrapped by the supplied SyntaxNodeOrToken.

Explicit(SyntaxNodeOrToken to SyntaxToken)

Returns the underlying token wrapped by the supplied SyntaxNodeOrToken.

Implicit(SyntaxNode to SyntaxNodeOrToken)

Returns a new SyntaxNodeOrToken that wraps the supplied node.

Implicit(SyntaxToken to SyntaxNodeOrToken)

Returns a new SyntaxNodeOrToken that wraps the supplied token.

Inequality(SyntaxNodeOrToken, SyntaxNodeOrToken)

Determines whether two SyntaxNodeOrTokens are unequal.

Extension Methods

Kind(SyntaxNodeOrToken)

Returns SyntaxKind for SyntaxNode from RawKind property.

IsKind(SyntaxNodeOrToken, SyntaxKind)

Determines if SyntaxNodeOrToken is of a specified kind.

Kind(SyntaxNodeOrToken)

Returns SyntaxKind for SyntaxNodeOrToken from RawKind property.

IsKind(SyntaxNodeOrToken, SyntaxKind)

Determines if SyntaxNodeOrToken is of a specified kind.

Applies to