Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 673
Beaker Avatar asked Feb 03 '13 03:02

Beaker


2 Answers

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'))

like image 81
Kevin Pilch Avatar answered Sep 28 '22 12:09

Kevin Pilch


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

like image 25
Richard Schneider Avatar answered Sep 28 '22 10:09

Richard Schneider