Struct SyntaxToken
Represents a token in the syntax tree.
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
Assembly: cs.temp.dll.dll
Syntax
public readonly struct SyntaxToken
Properties
ContainsAnnotations
True if this token or its trivia has any annotations.
Declaration
public readonly bool ContainsAnnotations { get; }
Property Value
Type |
Description |
System.Boolean |
|
ContainsDiagnostics
Determines whether this token or any of its descendant trivia have any diagnostics on them.
Declaration
public readonly bool ContainsDiagnostics { get; }
Property Value
Type |
Description |
System.Boolean |
|
ContainsDirectives
Determines whether this token has any descendant preprocessor directives.
Declaration
public readonly bool ContainsDirectives { get; }
Property Value
Type |
Description |
System.Boolean |
|
FullSpan
The absolute span of this token in characters, including its leading and trailing trivia.
Declaration
public readonly TextSpan FullSpan { get; }
Property Value
Type |
Description |
TextSpan |
|
HasLeadingTrivia
Determines whether this token has any leading trivia.
Declaration
public readonly bool HasLeadingTrivia { get; }
Property Value
Type |
Description |
System.Boolean |
|
HasStructuredTrivia
Determines whether any of this token's trivia is structured.
Declaration
public readonly bool HasStructuredTrivia { get; }
Property Value
Type |
Description |
System.Boolean |
|
HasTrailingTrivia
Determines whether this token has any trailing trivia.
Declaration
public readonly bool HasTrailingTrivia { get; }
Property Value
Type |
Description |
System.Boolean |
|
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.
Declaration
public readonly bool IsMissing { get; }
Property Value
Type |
Description |
System.Boolean |
|
Language
The language name that this token is syntax of.
Declaration
public readonly string Language { get; }
Property Value
Type |
Description |
System.String |
|
LeadingTrivia
The list of trivia that appear before this token in the source code.
Declaration
public readonly SyntaxTriviaList LeadingTrivia { get; }
Property Value
Parent
The node that contains this token in its Children collection.
Declaration
public readonly SyntaxNode Parent { get; }
Property Value
RawKind
An integer representing the language specific kind of this token.
Declaration
public readonly int RawKind { get; }
Property Value
Type |
Description |
System.Int32 |
|
Span
The absolute span of this token in characters, not including its leading and trailing trivia.
Declaration
public readonly TextSpan Span { get; }
Property Value
Type |
Description |
TextSpan |
|
SpanStart
Same as accessing on Span.
Declaration
public readonly int SpanStart { get; }
Property Value
Type |
Description |
System.Int32 |
|
SyntaxTree
The SyntaxTree that contains this token.
Declaration
public readonly SyntaxTree SyntaxTree { get; }
Property Value
Text
Declaration
public readonly string Text { get; }
Property Value
Type |
Description |
System.String |
|
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.
Declaration
public readonly SyntaxTriviaList TrailingTrivia { get; }
Property 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.
Declaration
public readonly object Value { get; }
Property Value
Type |
Description |
System.Object |
|
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.
Declaration
public readonly string ValueText { get; }
Property Value
Type |
Description |
System.String |
|
Methods
CopyAnnotationsTo(SyntaxToken)
Copies all SyntaxAnnotations, if any, from this SyntaxToken instance and attaches them to a new instance based on token
.
Declaration
public readonly SyntaxToken CopyAnnotationsTo(SyntaxToken token)
Parameters
Returns
Equals(SyntaxToken)
Declaration
public readonly bool Equals(SyntaxToken other)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Equals(Object)
Declaration
public override readonly bool Equals(object obj)
Parameters
Type |
Name |
Description |
System.Object |
obj |
|
Returns
Type |
Description |
System.Boolean |
|
Overrides
System.ValueType.Equals(System.Object)
GetAllTrivia()
Gets a list of all the trivia (both leading and trailing) for this token.
Declaration
public readonly IEnumerable<SyntaxTrivia> GetAllTrivia()
Returns
GetAnnotations(IEnumerable<String>)
Gets all the annotations of the specified annotation kind.
Declaration
public readonly IEnumerable<SyntaxAnnotation> GetAnnotations(IEnumerable<string> annotationKinds)
Parameters
Type |
Name |
Description |
IEnumerable<System.String> |
annotationKinds |
|
Returns
GetAnnotations(String)
Gets all the annotations of the specified annotation kind.
Declaration
public readonly IEnumerable<SyntaxAnnotation> GetAnnotations(string annotationKind)
Parameters
Type |
Name |
Description |
System.String |
annotationKind |
|
Returns
GetAnnotations(String[])
Gets all the annotations of the specified annotation kind.
Declaration
public readonly IEnumerable<SyntaxAnnotation> GetAnnotations(params string[] annotationKinds)
Parameters
Type |
Name |
Description |
System.String[] |
annotationKinds |
|
Returns
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.
Declaration
public readonly IEnumerable<Diagnostic> GetDiagnostics()
Returns
GetHashCode()
Declaration
public override readonly int GetHashCode()
Returns
Type |
Description |
System.Int32 |
|
Overrides
System.ValueType.GetHashCode()
GetLocation()
Gets the location for this token.
Declaration
public readonly Location GetLocation()
Returns
GetNextToken(Boolean, Boolean, Boolean, Boolean)
Gets the token that follows this token in the syntax tree.
Declaration
public readonly SyntaxToken GetNextToken(bool includeZeroWidth = false, bool includeSkipped = false, bool includeDirectives = false, bool includeDocumentationComments = false)
Parameters
Type |
Name |
Description |
System.Boolean |
includeZeroWidth |
|
System.Boolean |
includeSkipped |
|
System.Boolean |
includeDirectives |
|
System.Boolean |
includeDocumentationComments |
|
Returns
Type |
Description |
SyntaxToken |
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.
Declaration
public readonly SyntaxToken GetPreviousToken(bool includeZeroWidth = false, bool includeSkipped = false, bool includeDirectives = false, bool includeDocumentationComments = false)
Parameters
Type |
Name |
Description |
System.Boolean |
includeZeroWidth |
|
System.Boolean |
includeSkipped |
|
System.Boolean |
includeDirectives |
|
System.Boolean |
includeDocumentationComments |
|
Returns
Type |
Description |
SyntaxToken |
The next token that follows this token in the syntax tree.
|
HasAnnotation(SyntaxAnnotation)
True if this token has the specified annotation.
Declaration
public readonly bool HasAnnotation(SyntaxAnnotation annotation)
Parameters
Returns
Type |
Description |
System.Boolean |
|
HasAnnotations(String)
True if this token has annotations of the specified annotation kind.
Declaration
public readonly bool HasAnnotations(string annotationKind)
Parameters
Type |
Name |
Description |
System.String |
annotationKind |
|
Returns
Type |
Description |
System.Boolean |
|
HasAnnotations(String[])
True if this token has annotations of the specified annotation kinds.
Declaration
public readonly bool HasAnnotations(params string[] annotationKinds)
Parameters
Type |
Name |
Description |
System.String[] |
annotationKinds |
|
Returns
Type |
Description |
System.Boolean |
|
IsEquivalentTo(SyntaxToken)
Determines if this token is equivalent to the specified token.
Declaration
public readonly bool IsEquivalentTo(SyntaxToken token)
Parameters
Returns
Type |
Description |
System.Boolean |
|
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.
Declaration
public readonly bool IsIncrementallyIdenticalTo(SyntaxToken token)
Parameters
Returns
Type |
Description |
System.Boolean |
|
IsPartOfStructuredTrivia()
Determines whether this token is a descendant of a structured trivia.
Declaration
public readonly bool IsPartOfStructuredTrivia()
Returns
Type |
Description |
System.Boolean |
|
ToFullString()
Returns the full string representation of this token including its leading and trailing trivia.
Declaration
public readonly string ToFullString()
Returns
Type |
Description |
System.String |
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.
Declaration
public override readonly string ToString()
Returns
Type |
Description |
System.String |
The string representation of this token, not including its leading and trailing trivia.
|
Overrides
System.ValueType.ToString()
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.
Declaration
public readonly SyntaxToken WithAdditionalAnnotations(IEnumerable<SyntaxAnnotation> annotations)
Parameters
Returns
WithAdditionalAnnotations(SyntaxAnnotation[])
Adds this annotation to a given syntax token, creating a new syntax token of the same type with the
annotation on it.
Declaration
public readonly SyntaxToken WithAdditionalAnnotations(params SyntaxAnnotation[] annotations)
Parameters
Returns
WithLeadingTrivia(SyntaxTrivia[])
Creates a new token from this token with the leading trivia specified..
Declaration
public readonly SyntaxToken WithLeadingTrivia(params SyntaxTrivia[] trivia)
Parameters
Returns
WithLeadingTrivia(SyntaxTriviaList)
Creates a new token from this token with the leading trivia specified.
Declaration
public readonly SyntaxToken WithLeadingTrivia(SyntaxTriviaList trivia)
Parameters
Returns
WithLeadingTrivia(Nullable<IEnumerable<SyntaxTrivia>>)
Creates a new token from this token with the leading trivia specified.
Declaration
public readonly SyntaxToken WithLeadingTrivia(IEnumerable<SyntaxTrivia>? trivia)
Parameters
Type |
Name |
Description |
System.Nullable<IEnumerable<SyntaxTrivia>> |
trivia |
|
Returns
WithoutAnnotations(IEnumerable<SyntaxAnnotation>)
Creates a new syntax token identical to this one without the specified annotations.
Declaration
public readonly SyntaxToken WithoutAnnotations(IEnumerable<SyntaxAnnotation> annotations)
Parameters
Returns
WithoutAnnotations(SyntaxAnnotation[])
Creates a new syntax token identical to this one without the specified annotations.
Declaration
public readonly SyntaxToken WithoutAnnotations(params SyntaxAnnotation[] annotations)
Parameters
Returns
WithoutAnnotations(String)
Creates a new syntax token identical to this one without annotations of the specified kind.
Declaration
public readonly SyntaxToken WithoutAnnotations(string annotationKind)
Parameters
Type |
Name |
Description |
System.String |
annotationKind |
|
Returns
WithTrailingTrivia(SyntaxTrivia[])
Creates a new token from this token with the trailing trivia specified.
Declaration
public readonly SyntaxToken WithTrailingTrivia(params SyntaxTrivia[] trivia)
Parameters
Returns
WithTrailingTrivia(SyntaxTriviaList)
Creates a new token from this token with the trailing trivia specified.
Declaration
public readonly SyntaxToken WithTrailingTrivia(SyntaxTriviaList trivia)
Parameters
Returns
WithTrailingTrivia(Nullable<IEnumerable<SyntaxTrivia>>)
Creates a new token from this token with the trailing trivia specified.
Declaration
public readonly SyntaxToken WithTrailingTrivia(IEnumerable<SyntaxTrivia>? trivia)
Parameters
Type |
Name |
Description |
System.Nullable<IEnumerable<SyntaxTrivia>> |
trivia |
|
Returns
WithTriviaFrom(SyntaxToken)
Creates a new token from this token with the leading and trailing trivia from the specified token.
Declaration
public readonly SyntaxToken WithTriviaFrom(SyntaxToken token)
Parameters
Returns
WriteTo(TextWriter)
Writes the full text of this token to the specified writer
.
Declaration
public readonly void WriteTo(TextWriter writer)
Parameters
Type |
Name |
Description |
System.IO.TextWriter |
writer |
|
Operators
Equality(SyntaxToken, SyntaxToken)
Declaration
public static bool operator ==(SyntaxToken left, SyntaxToken right)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Inequality(SyntaxToken, SyntaxToken)
Declaration
public static bool operator !=(SyntaxToken left, SyntaxToken right)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Implements
IEquatable<>