SyntaxToken Struct

Definition

Represents a token in the syntax tree.

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

Properties

ContainsAnnotations

True if this token or its trivia has any annotations.

ContainsDiagnostics

Determines whether this token or any of its descendant trivia have any diagnostics on them.

ContainsDirectives

Determines whether this token has any descendant preprocessor directives.

FullSpan

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

HasLeadingTrivia

Determines whether this token has any leading trivia.

HasStructuredTrivia

Determines whether any of this token's trivia is structured.

HasTrailingTrivia

Determines whether this token has any trailing trivia.

IsMissing

Determines whether this token represents a language construct that was actually parsed from source code. Missing 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.

Language

The language name that this token is syntax of.

LeadingTrivia

The list of trivia that appear before this token in the source code.

Parent

The node that contains this token in its Children collection.

RawKind

An integer representing the language specific kind of this token.

Span

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

SpanStart

Same as accessing Start on Span.

SyntaxTree

The SyntaxTree that contains this token.

Text
TrailingTrivia

The list of trivia that appear after this token in the source code and are attached to this token or any of its descendants.

Value

Returns the value of the token. For example, if the token represents an integer literal, then this property would return the actual integer.

ValueText

Returns the text representation of the value of the token. For example, if the token represents an integer literal, then this property would return a string representing the integer.

Methods

CopyAnnotationsTo(SyntaxToken)

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

Equals(Object)

Determines whether the supplied SyntaxToken is equal to this SyntaxToken.

Equals(SyntaxToken)

Determines whether the supplied SyntaxToken is equal to this SyntaxToken.

GetAllTrivia()

Gets a list of all the trivia (both leading and trailing) for this token.

GetAnnotations(IEnumerable<String>)

Gets all the annotations of the specified annotation kind.

GetAnnotations(String)

Gets all the annotations of the specified annotation kind.

GetAnnotations(String[])

Gets all the annotations of the specified annotation kind.

GetDiagnostics()

Gets a list of all the diagnostics associated with this token and any related trivia. This method does not filter diagnostics based on #pragmas and compiler options like nowarn, warnaserror etc.

GetHashCode()

Serves as hash function for SyntaxToken.

GetLocation()

Gets the location for this token.

GetNextToken(Boolean, Boolean, Boolean, Boolean)

Gets the token that follows this token in the syntax tree.

GetPreviousToken(Boolean, Boolean, Boolean, Boolean)

Gets the token that precedes this token in the syntax tree.

HasAnnotation(SyntaxAnnotation)

True if this token has the specified annotation.

HasAnnotations(String)

True if this token has annotations of the specified annotation kind.

HasAnnotations(String[])

True if this token has annotations of the specified annotation kinds.

IsEquivalentTo(SyntaxToken)

Determines if this token is equivalent to the specified token.

IsIncrementallyIdenticalTo(SyntaxToken)

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

IsPartOfStructuredTrivia()

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

ToFullString()

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

ToString()

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

WithAdditionalAnnotations(IEnumerable<SyntaxAnnotation>)

Adds this annotation to a given syntax token, creating a new syntax token of the same type with the annotation on it.

WithAdditionalAnnotations(SyntaxAnnotation[])

Adds this annotation to a given syntax token, creating a new syntax token of the same type with the annotation on it.

WithLeadingTrivia(IEnumerable<SyntaxTrivia>)

Creates a new token from this token with the leading trivia specified.

WithLeadingTrivia(SyntaxTrivia[])

Creates a new token from this token with the leading trivia specified..

WithLeadingTrivia(SyntaxTriviaList)

Creates a new token from this token with the leading trivia specified.

WithoutAnnotations(IEnumerable<SyntaxAnnotation>)

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

WithoutAnnotations(String)

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

WithoutAnnotations(SyntaxAnnotation[])

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

WithTrailingTrivia(IEnumerable<SyntaxTrivia>)

Creates a new token from this token with the trailing trivia specified.

WithTrailingTrivia(SyntaxTrivia[])

Creates a new token from this token with the trailing trivia specified.

WithTrailingTrivia(SyntaxTriviaList)

Creates a new token from this token with the trailing trivia specified.

WithTriviaFrom(SyntaxToken)

Creates a new token from this token with the leading and trailing trivia from the specified token.

WriteTo(TextWriter)

Writes the full text of this token to the specified writer.

Operators

Equality(SyntaxToken, SyntaxToken)

Determines whether two SyntaxTokens are equal.

Inequality(SyntaxToken, SyntaxToken)

Determines whether two SyntaxTokens are unequal.

Extension Methods

IsContextualKeyword(SyntaxToken)
IsKeyword(SyntaxToken)
IsReservedKeyword(SyntaxToken)
IsVerbatimIdentifier(SyntaxToken)
IsVerbatimStringLiteral(SyntaxToken)
Kind(SyntaxToken)

Returns SyntaxKind for SyntaxToken from RawKind property.

ReplaceTrivia(SyntaxToken, SyntaxTrivia, SyntaxTrivia)

Creates a new token with the specified old trivia replaced with a new trivia. The old trivia may appear in the token's leading or trailing trivia.

ReplaceTrivia(SyntaxToken, IEnumerable<SyntaxTrivia>, Func<SyntaxTrivia,SyntaxTrivia,SyntaxTrivia>)

Creates a new token with the specified old trivia replaced with computed new trivia.

VarianceKindFromToken(SyntaxToken)
NormalizeWhitespace(SyntaxToken, String, Boolean)

Creates a new syntax token with all whitespace and end of line trivia replaced with regularly formatted trivia.

NormalizeWhitespace(SyntaxToken, String, String, Boolean)

Creates a new syntax token with all whitespace and end of line trivia replaced with regularly formatted trivia.

IsKind(SyntaxToken, SyntaxKind)

Determines if SyntaxToken is of a specified kind.

WithoutTrivia(SyntaxToken)

Creates a new token from this token without leading or trailing trivia.

NormalizeWhitespace(SyntaxToken, String, Boolean)
NormalizeWhitespace(SyntaxToken, String, String, Boolean, Boolean)
GetBase(SyntaxToken)

The source token base for Integer literals. Base can be Decimal, Hex or Octal.

GetIdentifierText(SyntaxToken)

Returns the Identifiertext for a specified SyntaxToken.

GetTypeCharacter(SyntaxToken)

Returns the Type character for a given syntax token. This returns type character for Identifiers or Integer, Floating Point or Decimal Literals. Examples: Dim a$ or Dim l1 = 1L

IsBracketed(SyntaxToken)

Checks to see if SyntaxToken is a bracketed identifier.

IsContextualKeyword(SyntaxToken)

Determines if the token represents a contextual keyword

IsKeyword(SyntaxToken)

Determines if the token represents a reserved or contextual keyword

IsPreprocessorKeyword(SyntaxToken)

Determines if the token represents a preprocessor keyword

IsReservedKeyword(SyntaxToken)

Determines if the token represents a reserved keyword

Kind(SyntaxToken)

Returns SyntaxKind for SyntaxToken from RawKind property.

ReplaceTrivia(SyntaxToken, SyntaxTrivia, SyntaxTrivia)

Replaces trivia on a specified SyntaxToken.

ReplaceTrivia(SyntaxToken, IEnumerable<SyntaxTrivia>, Func<SyntaxTrivia,SyntaxTrivia,SyntaxTrivia>)

Replaces trivia on a specified SyntaxToken.

IsKind(SyntaxToken, SyntaxKind)

Determines if SyntaxToken is of a specified kind.

Applies to