LiteralExpression - ArgumentOutOfRangeException

In life, I cannot understand why this line of code:

var literalExpressionSyntax = 
     Syntax.LiteralExpression(SyntaxKind.CharacterLiteralExpression);

throws out ArgumentOutOfRangeExceptionin accordance with Roslyn CTP3.

+5
source share
2 answers

The reason the second parameter is optional is because the text is implied for some values SyntaxKind. For example, if you pass SyntaxKind.TrueLiteralfor the first argument, you can omit the second. However, when there is no reasonable default value for the second parameter based on the first parameter, we give up ArgumentOutOfRangeException.

In your example, you can create an expression with:

Syntax.LiteralExpression(SyntaxKind.CharacterLiteralExpression, Syntax.Literal('a'))

+3
source

Shouldn't you specify the second argument, which is the actual literal.

+2
source

All Articles