Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what situation might Text be different from ValueText

Tags:

c#

roslyn

In Roslyn (Microsoft.CodeAnalysis), SyntaxTokens have Text and ValueText fields. In all of the situations that I've observed so far, these two values are the same. ValueText has documentation while Text does not. As far as I can tell, that's the only difference.

Why do both exist? In what situation would they be different, and why?

like image 779
M-Pixel Avatar asked Oct 04 '17 21:10

M-Pixel


1 Answers

Why do both exist?

Because they're sometimes different and both are useful.

In what situation would they be different, and why?

int @interface = 123;

The Text of the @interface token is @interface. The ValueText is interface. The text tell you what is the text as it appeared in the source code. The value text tells you logically, what is the text of this thing? An escaped keyword used as an identifier is logically the text of the keyword; that's the name of the identifier.

There are other situations in which the text and the value text can be different; see if you can find some.

like image 82
Eric Lippert Avatar answered Oct 20 '22 00:10

Eric Lippert