In Roslyn CTP the following signature of methods is used quite commonly:
LiteralExpressionSyntax LiteralExpression(SyntaxKind kind, SyntaxToken token)
What is the reason for passing SyntaxKind? token
itself has Kind
property, why Roslyn do not use it?
To be more precise, it takes user-provided kind
, asserts that it is limited to a narrow set of values, then checks that token
's Kind
also belongs to this narrow set, and then passes user-provided kind
further.
Why Roslyn not uses token.Kind
and makes user to pass explicit kind?
UPD: Actually, the main question is: what are situations when kind
, passed by user, will be different than token
's kind?
If you look closely, you'll see that the kinds checked are not actually the same in each case. There are separate SyntaxKinds
for and expressions - so you would have a SyntaxKind.TrueKeyword
for the token, and SyntaxKind.TrueLiteralExpression
for the resulting LiteralExpressionSyntax
. To answer your updated question, the resulting expression.Kind
will never match the token.Kind
.
However, it does appear to be the case that there is a one-to-one correspondence of token kinds to expression kinds in this case, which means we could derive the expression kind from the token kind. I'll raise this internally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With