Skip to content

Why is SyntaxToken.RawContextualKind internal? #6822

@jnm2

Description

@jnm2

If I understand correctly, I'm currently forced to use a string comparison to determine if an invocation expression is nameof, vs some method or delegate:

if ((invocationExpression as IdentifierNameSyntax)?.Identifier.ValueText ==
    SyntaxFactory.Token(SyntaxKind.NameOfKeyword).ValueText) [...]

I would much prefer access to RawContextualKind and the ContextualKind() extension method just like RawKind and Kind(). Right off the bat it feels cleaner and more performant. Besides that and perhaps more importantly, nameof is a contextual keyword. Sometimes the same token value string could be used for NameOfKeyword, and sometimes it might refer to a method or delegate. The XML docs on RawContextualKind confirm that this is relevant for contexual keywords. This code would be much smarter:

if ((invocationExpression as IdentifierNameSyntax)?.Identifier.ContextualKind() ==
    SyntaxKind.NameOfKeyword) [...]

Why is the contextual syntactic knowledge stored in RawContextualKind barred from public access? Is there a different API that does provide access?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.QuestionResolution-AnsweredThe question has been answered

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions