SyntaxToken SyntaxToken SyntaxToken SyntaxToken Struct

Definition

Represents a token in the syntax tree. This is the language agnostic equivalent of Microsoft.CodeAnalysis.CSharp.SyntaxToken and Microsoft.CodeAnalysis.VisualBasic.SyntaxToken.

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

Properties

ContainsAnnotations ContainsAnnotations ContainsAnnotations ContainsAnnotations

True if this token or its trivia has any annotations.

ContainsDiagnostics ContainsDiagnostics ContainsDiagnostics ContainsDiagnostics

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

ContainsDirectives ContainsDirectives ContainsDirectives ContainsDirectives

Determines whether this token has any descendant preprocessor directives.

FullSpan FullSpan FullSpan FullSpan

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

HasLeadingTrivia HasLeadingTrivia HasLeadingTrivia HasLeadingTrivia

Determines whether this token has any leading trivia.

HasStructuredTrivia HasStructuredTrivia HasStructuredTrivia HasStructuredTrivia

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

HasTrailingTrivia HasTrailingTrivia HasTrailingTrivia HasTrailingTrivia

Determines whether this token has any trailing trivia.

IsMissing IsMissing IsMissing 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 Language Language Language

The language name that this token is syntax of.

LeadingTrivia LeadingTrivia LeadingTrivia LeadingTrivia

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

Parent Parent Parent Parent

The node that contains this token in its Children collection.

RawKind RawKind RawKind RawKind

An integer representing the language specific kind of this token.

Span Span Span Span

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

SpanStart SpanStart SpanStart SpanStart

Same as accessing Start on Span.

SyntaxTree SyntaxTree SyntaxTree SyntaxTree

The SyntaxTree that contains this token.

Text Text Text Text
TrailingTrivia TrailingTrivia TrailingTrivia 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 Value Value 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 ValueText ValueText 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) CopyAnnotationsTo(SyntaxToken) CopyAnnotationsTo(SyntaxToken) CopyAnnotationsTo(SyntaxToken)

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

Equals(SyntaxToken) Equals(SyntaxToken) Equals(SyntaxToken) Equals(SyntaxToken)

Determines whether the supplied SyntaxToken is equal to this SyntaxToken.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the supplied SyntaxToken is equal to this SyntaxToken.

GetAllTrivia() GetAllTrivia() GetAllTrivia() GetAllTrivia()

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

GetAnnotations(IEnumerable<String>) GetAnnotations(IEnumerable<String>) GetAnnotations(IEnumerable<String>) GetAnnotations(IEnumerable<String>)

Gets all the annotations of the specified annotation kind.

GetAnnotations(String) GetAnnotations(String) GetAnnotations(String) GetAnnotations(String)

Gets all the annotations of the specified annotation kind.

GetAnnotations(String[]) GetAnnotations(String[]) GetAnnotations(String[]) GetAnnotations(String[])

Gets all the annotations of the specified annotation kind.

GetDiagnostics() GetDiagnostics() GetDiagnostics() 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() GetHashCode() GetHashCode() GetHashCode()

Serves as hash function for SyntaxToken.

GetLocation() GetLocation() GetLocation() GetLocation()

Gets the location for this token.

GetNextToken(Boolean, Boolean, Boolean, Boolean) GetNextToken(Boolean, Boolean, Boolean, Boolean) GetNextToken(Boolean, Boolean, Boolean, Boolean) GetNextToken(Boolean, Boolean, Boolean, Boolean)

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

GetPreviousToken(Boolean, Boolean, Boolean, Boolean) GetPreviousToken(Boolean, Boolean, Boolean, Boolean) GetPreviousToken(Boolean, Boolean, Boolean, Boolean) GetPreviousToken(Boolean, Boolean, Boolean, Boolean)

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

HasAnnotation(SyntaxAnnotation) HasAnnotation(SyntaxAnnotation) HasAnnotation(SyntaxAnnotation) HasAnnotation(SyntaxAnnotation)

True if this token has the specified annotation.

HasAnnotations(String) HasAnnotations(String) HasAnnotations(String) HasAnnotations(String)

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

HasAnnotations(String[]) HasAnnotations(String[]) HasAnnotations(String[]) HasAnnotations(String[])

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

IsEquivalentTo(SyntaxToken) IsEquivalentTo(SyntaxToken) IsEquivalentTo(SyntaxToken) IsEquivalentTo(SyntaxToken)

Determines if this token is equivalent to the specified token.

IsPartOfStructuredTrivia() IsPartOfStructuredTrivia() IsPartOfStructuredTrivia() IsPartOfStructuredTrivia()

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

ToFullString() ToFullString() ToFullString() ToFullString()

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

ToString() ToString() ToString() ToString()

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

WithAdditionalAnnotations(SyntaxAnnotation[]) WithAdditionalAnnotations(SyntaxAnnotation[]) WithAdditionalAnnotations(SyntaxAnnotation[]) WithAdditionalAnnotations(SyntaxAnnotation[])

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

WithAdditionalAnnotations(IEnumerable<SyntaxAnnotation>) WithAdditionalAnnotations(IEnumerable<SyntaxAnnotation>) WithAdditionalAnnotations(IEnumerable<SyntaxAnnotation>) 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.

WithLeadingTrivia(SyntaxTrivia[]) WithLeadingTrivia(SyntaxTrivia[]) WithLeadingTrivia(SyntaxTrivia[]) WithLeadingTrivia(SyntaxTrivia[])

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

WithLeadingTrivia(SyntaxTriviaList) WithLeadingTrivia(SyntaxTriviaList) WithLeadingTrivia(SyntaxTriviaList) WithLeadingTrivia(SyntaxTriviaList)

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

WithLeadingTrivia(IEnumerable<SyntaxTrivia>) WithLeadingTrivia(IEnumerable<SyntaxTrivia>) WithLeadingTrivia(IEnumerable<SyntaxTrivia>) WithLeadingTrivia(IEnumerable<SyntaxTrivia>)

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

WithoutAnnotations(SyntaxAnnotation[]) WithoutAnnotations(SyntaxAnnotation[]) WithoutAnnotations(SyntaxAnnotation[]) WithoutAnnotations(SyntaxAnnotation[])

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

WithoutAnnotations(IEnumerable<SyntaxAnnotation>) WithoutAnnotations(IEnumerable<SyntaxAnnotation>) WithoutAnnotations(IEnumerable<SyntaxAnnotation>) WithoutAnnotations(IEnumerable<SyntaxAnnotation>)

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

WithoutAnnotations(String) WithoutAnnotations(String) WithoutAnnotations(String) WithoutAnnotations(String)

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

WithTrailingTrivia(SyntaxTrivia[]) WithTrailingTrivia(SyntaxTrivia[]) WithTrailingTrivia(SyntaxTrivia[]) WithTrailingTrivia(SyntaxTrivia[])

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

WithTrailingTrivia(SyntaxTriviaList) WithTrailingTrivia(SyntaxTriviaList) WithTrailingTrivia(SyntaxTriviaList) WithTrailingTrivia(SyntaxTriviaList)

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

WithTrailingTrivia(IEnumerable<SyntaxTrivia>) WithTrailingTrivia(IEnumerable<SyntaxTrivia>) WithTrailingTrivia(IEnumerable<SyntaxTrivia>) WithTrailingTrivia(IEnumerable<SyntaxTrivia>)

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

WithTriviaFrom(SyntaxToken) WithTriviaFrom(SyntaxToken) WithTriviaFrom(SyntaxToken) WithTriviaFrom(SyntaxToken)

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

WriteTo(TextWriter) WriteTo(TextWriter) WriteTo(TextWriter) WriteTo(TextWriter)

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

Operators

Equality(SyntaxToken, SyntaxToken) Equality(SyntaxToken, SyntaxToken) Equality(SyntaxToken, SyntaxToken) Equality(SyntaxToken, SyntaxToken)

Determines whether two SyntaxTokens are equal.

Inequality(SyntaxToken, SyntaxToken) Inequality(SyntaxToken, SyntaxToken) Inequality(SyntaxToken, SyntaxToken) Inequality(SyntaxToken, SyntaxToken)

Determines whether two SyntaxTokens are unequal.

Extension Methods

IsContextualKeyword(SyntaxToken) IsContextualKeyword(SyntaxToken) IsContextualKeyword(SyntaxToken) IsContextualKeyword(SyntaxToken)
IsKeyword(SyntaxToken) IsKeyword(SyntaxToken) IsKeyword(SyntaxToken) IsKeyword(SyntaxToken)
IsReservedKeyword(SyntaxToken) IsReservedKeyword(SyntaxToken) IsReservedKeyword(SyntaxToken) IsReservedKeyword(SyntaxToken)
IsVerbatimIdentifier(SyntaxToken) IsVerbatimIdentifier(SyntaxToken) IsVerbatimIdentifier(SyntaxToken) IsVerbatimIdentifier(SyntaxToken)
IsVerbatimStringLiteral(SyntaxToken) IsVerbatimStringLiteral(SyntaxToken) IsVerbatimStringLiteral(SyntaxToken) IsVerbatimStringLiteral(SyntaxToken)
Kind(SyntaxToken) Kind(SyntaxToken) Kind(SyntaxToken) Kind(SyntaxToken)
ReplaceTrivia(SyntaxToken, SyntaxTrivia, SyntaxTrivia) ReplaceTrivia(SyntaxToken, SyntaxTrivia, SyntaxTrivia) ReplaceTrivia(SyntaxToken, SyntaxTrivia, SyntaxTrivia) 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>) ReplaceTrivia(SyntaxToken, IEnumerable<SyntaxTrivia>, Func<SyntaxTrivia,SyntaxTrivia,SyntaxTrivia>) ReplaceTrivia(SyntaxToken, IEnumerable<SyntaxTrivia>, Func<SyntaxTrivia,SyntaxTrivia,SyntaxTrivia>) ReplaceTrivia(SyntaxToken, IEnumerable<SyntaxTrivia>, Func<SyntaxTrivia,SyntaxTrivia,SyntaxTrivia>)

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

VarianceKindFromToken(SyntaxToken) VarianceKindFromToken(SyntaxToken) VarianceKindFromToken(SyntaxToken) VarianceKindFromToken(SyntaxToken)
NormalizeWhitespace(SyntaxToken, String, Boolean) NormalizeWhitespace(SyntaxToken, String, Boolean) NormalizeWhitespace(SyntaxToken, String, Boolean) 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) NormalizeWhitespace(SyntaxToken, String, String, Boolean) NormalizeWhitespace(SyntaxToken, String, String, Boolean) 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) IsKind(SyntaxToken, SyntaxKind) IsKind(SyntaxToken, SyntaxKind) IsKind(SyntaxToken, SyntaxKind)
WithoutTrivia(SyntaxToken) WithoutTrivia(SyntaxToken) WithoutTrivia(SyntaxToken) WithoutTrivia(SyntaxToken)

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

Applies to