Click or drag to resize

SyntaxToken Class



Represents a token in the syntax tree. This is the language agnostic equivalent of SyntaxToken and SyntaxToken.
Inheritance Hierarchy
SystemValueType
  Microsoft.CodeAnalysisSyntaxToken

Namespace:  Microsoft.CodeAnalysis
Assembly:  Microsoft.CodeAnalysis (in Microsoft.CodeAnalysis.dll) Version: 2.3.0-dev-56735-00. Commit Hash: <developer build>
Syntax
public sealed class SyntaxToken : ValueType, 
	IEquatable

The SyntaxToken type exposes the following members.

Properties
  NameDescription
Public propertyContainsAnnotations
True if this token or its trivia has any annotations.
Public propertyContainsDiagnostics
Determines whether this token or any of its descendant trivia have any diagnostics on them.
Public propertyContainsDirectives
Determines whether this token has any descendant preprocessor directives.
Public propertyFullSpan
The absolute span of this token in characters, including its leading and trailing trivia.
Public propertyHasLeadingTrivia
Determines whether this token has any leading trivia.
Public propertyHasStructuredTrivia
Determines whether any of this token's trivia is structured.
Public propertyHasTrailingTrivia
Determines whether this token has any trailing trivia.
Public propertyIsMissing
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.
Public propertyLanguage
The language name that this token is syntax of.
Public propertyLeadingTrivia
The list of trivia that appear before this token in the source code.
Public propertyParent
The node that contains this token in its Children collection.
Public propertyRawKind
An integer representing the language specific kind of this token.
Public propertySpan
The absolute span of this token in characters, not including its leading and trailing trivia.
Public propertySpanStart
Same as accessing Start on Span.
Public propertySyntaxTree
The SyntaxTree that contains this token.
Public propertyText
Public propertyTrailingTrivia
The list of trivia that appear after this token in the source code and are attached to this token or any of its descendants.
Public propertyValue
Returns the value of the token. For example, if the token represents an integer literal, then this property would return the actual integer.
Public propertyValueText
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.
Top
Methods
  NameDescription
Public methodCopyAnnotationsTo
Copies all SyntaxAnnotations, if any, from this SyntaxToken instance and attaches them to a new instance based on token.
Public methodEquals(Object)
Determines whether the supplied SyntaxToken is equal to this SyntaxToken.
Public methodEquals(SyntaxToken)
Determines whether the supplied SyntaxToken is equal to this SyntaxToken.
Public methodGetAllTrivia
Gets a list of all the trivia (both leading and trailing) for this token.
Public methodGetAnnotations(Void)
Public methodGetDiagnostics
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.
Public methodGetHashCode
Serves as hash function for SyntaxToken.
Public methodGetLocation
Gets the location for this token.
Public methodGetNextToken
Gets the token that follows this token in the syntax tree.
Public methodGetPreviousToken
Gets the token that precedes this token in the syntax tree.
Public methodHasAnnotation
True if this token has the specified annotation.
Public methodHasAnnotations(String)
True if this token has annotations of the specified annotation kind.
Public methodHasAnnotations(String)
True if this token has annotations of the specified annotation kinds.
Public methodIsEquivalentTo
Determines if this token is equivalent to the specified token.
Public methodIsPartOfStructuredTrivia
Determines whether this token is a descendant of a structured trivia.
Public methodToFullString
Returns the full string representation of this token including its leading and trailing trivia.
Public methodToString
Returns the string representation of this token, not including its leading and trailing trivia.
Public methodWithAdditionalAnnotations(IEnumerableT)
Public methodWithAdditionalAnnotations(SyntaxAnnotation)
Adds this annotation to a given syntax token, creating a new syntax token of the same type with the annotation on it.
Public methodWithLeadingTrivia(IEnumerableT)
Public methodWithLeadingTrivia(SyntaxTrivia)
Creates a new token from this token with the leading trivia specified..
Public methodWithLeadingTrivia(SyntaxTriviaList)
Creates a new token from this token with the leading trivia specified.
Public methodWithoutAnnotations(IEnumerableT)
Public methodWithoutAnnotations(String)
Creates a new syntax token identical to this one without annotations of the specified kind.
Public methodWithoutAnnotations(SyntaxAnnotation)
Creates a new syntax token identical to this one without the specified annotations.
Public methodWithTrailingTrivia(IEnumerableT)
Public methodWithTrailingTrivia(SyntaxTrivia)
Creates a new token from this token with the trailing trivia specified.
Public methodWithTrailingTrivia(SyntaxTriviaList)
Creates a new token from this token with the trailing trivia specified.
Public methodWithTriviaFrom
Creates a new token from this token with the leading and trailing trivia from the specified token.
Public methodWriteTo
Writes the full text of this token to the specified writer.
Top
Operators
  NameDescription
Public operatorStatic memberEquality
Determines whether two SyntaxTokens are equal.
Public operatorStatic memberInequality
Determines whether two SyntaxTokens are unequal.
Top
Extension Methods
  NameDescription
Public Extension MethodGetIdentifierText
Returns the Identifiertext for a specified SyntaxToken.
(Defined by VisualBasicExtensions.)
Public Extension MethodGetTypeCharacter
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
(Defined by VisualBasicExtensions.)
Public Extension MethodIsBracketed
Checks to see if SyntaxToken is a bracketed identifier.
(Defined by VisualBasicExtensions.)
Public Extension MethodIsContextualKeywordOverloaded.
Determines if the token represents a contextual keyword
(Defined by VisualBasicExtensions.)
Public Extension MethodIsContextualKeywordOverloaded. (Defined by CSharpExtensions.)
Public Extension MethodIsKeywordOverloaded.
Determines if the token represents a reserved or contextual keyword
(Defined by VisualBasicExtensions.)
Public Extension MethodIsKeywordOverloaded. (Defined by CSharpExtensions.)
Public Extension MethodIsKind(SyntaxKind)Overloaded.
Determines if SyntaxToken is a specified kind.
(Defined by VisualBasicExtensions.)
Public Extension MethodIsKind(SyntaxKind)Overloaded. (Defined by CSharpExtensions.)
Public Extension MethodIsPreprocessorKeyword
Determines if the token represents a preprocessor keyword
(Defined by VisualBasicExtensions.)
Public Extension MethodIsReservedKeywordOverloaded.
Determines if the token represents a reserved keyword
(Defined by VisualBasicExtensions.)
Public Extension MethodIsReservedKeywordOverloaded. (Defined by CSharpExtensions.)
Public Extension MethodIsVerbatimIdentifier (Defined by CSharpExtensions.)
Public Extension MethodIsVerbatimStringLiteral (Defined by CSharpExtensions.)
Public Extension MethodKindOverloaded.
Returns SyntaxKind for SyntaxToken from RawKind property.
(Defined by VisualBasicExtensions.)
Public Extension MethodKindOverloaded. (Defined by CSharpExtensions.)
Public Extension MethodNormalizeWhitespace(String, Boolean)Overloaded. (Defined by SyntaxExtensions.)
Public Extension MethodNormalizeWhitespace(String, Boolean)Overloaded.
Creates a new syntax token with all whitespace and end of line trivia replaced with regularly formatted trivia.
(Defined by SyntaxExtensions.)
Public Extension MethodNormalizeWhitespace(String, String, Boolean)Overloaded.
Creates a new syntax token with all whitespace and end of line trivia replaced with regularly formatted trivia.
(Defined by SyntaxExtensions.)
Public Extension MethodNormalizeWhitespace(String, String, Boolean, Boolean)Overloaded. (Defined by SyntaxExtensions.)
Public Extension MethodReplaceTrivia(IEnumerableT, Void)Overloaded. (Defined by VisualBasicExtensions.)
Public Extension MethodReplaceTrivia(IEnumerableT, Void)Overloaded. (Defined by CSharpExtensions.)
Public Extension MethodReplaceTrivia(SyntaxTrivia, SyntaxTrivia)Overloaded.
Replaces trivia on a specified SyntaxToken.
(Defined by VisualBasicExtensions.)
Public Extension MethodReplaceTrivia(SyntaxTrivia, SyntaxTrivia)Overloaded.
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.
(Defined by CSharpExtensions.)
Public Extension MethodVarianceKindFromToken (Defined by CSharpExtensions.)
Public Extension MethodWithoutTrivia
Creates a new token from this token without leading or trailing trivia.
(Defined by SyntaxNodeExtensions.)
Top
See Also