Beaker
Beaker

Reputation: 2894

LiteralExpression - ArgumentOutOfRangeException

For the life of me, I cannot figure out why this line of code:

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

throws an ArgumentOutOfRangeException under Roslyn CTP3.

Upvotes: 5

Views: 181

Answers (2)

Kevin Pilch
Kevin Pilch

Reputation: 11615

The reason the second parameter is optional is that the text is implied for some SyntaxKind values. For example, if you pass SyntaxKind.TrueLiteral for the first argument, then you can omit the second one. However, when there is no reasonable default for the second parameter based on the first parameter, we throw the ArgumentOutOfRangeException.

In your example, you can create the expression with:

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

Upvotes: 3

Richard Schneider
Richard Schneider

Reputation: 35477

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

Upvotes: 2

Related Questions