我写了一个程序(C#)读取和操作已经从C#程序生成的MSIL程序。我曾错误地认为,对于MSIL字符串常量的语法规则都是一样的C#,但后来我碰到了下面的情况:
I've written a program (in C#) that reads and manipulates MSIL programs that have been generated from C# programs. I had mistakenly assumed that the syntax rules for MSIL string constants are the same as for C#, but then I ran into the following situation:
本C#声明
string s = "Do you wish to send anyway?";
被编译成(其中包括MSIL语句)这个
gets compiled into (among other MSIL statements) this
IL_0128: ldstr "Do you wish to send anyway?"
我没想到这是用来逃跑的问号反斜线。现在我可以很明显借此反斜杠考虑作为我处理的一部分,但大多是出于好奇,我想知道是否有一个清单某处其中的字符获取逃脱,当C#编译器C#常量字符串转换成MSIL常量字符串。
I wasn't expecting the backslash that is used to escape the question mark. Now I can obviously take this backslash into account as part of my processing, but mostly out of curiosity I'd like to know if there is a list somewhere of which characters get escaped when the C# compiler converts C# constant strings to MSIL constant strings.
感谢。
推荐答案
更新
+程序Ildasm.exe:也许有转义字符没有名单的原因是因为有这么几个:precisely 6.
Based on experimentation using the C# compiler + ildasm.exe: perhaps the reason there is no list of escaped characters is because there are so few: precisely 6.
从ILDASM生成的IL去,从Visual Studio 2010中编译的C#程序的:
在IL严格的 ASCII 在三个传统的空格字符转义 t
:×09(片)
ñ
:的0x0A(新行)
r
:0X0D(回车)
IL is strictly ASCII.
Three traditional whitespace characters are escaped
t
: 0x09 : (tab)
n
: 0x0A : (newline)
r
: 0x0D : (carriage return)
:输入0x22:(双引号)
:0x3F的:(问号)
:0x5c的:(反斜线)
"
: 0x22 : (double quote)
?
: 0x3F : (question mark)
: 0x5C : (backslash)
例1:的ASCII以上0x7E的:一个简单的重音E(U + 00E9)
Example 1: ASCII above 0x7E: A simple accented é (U+00E9)
C#:无论是é
或 u00E9
变( E9
字节来自第一的)
C#: Either "é"
or "u00E9"
becomes (E9
byte comes first)
ldstr bytearray (E9 00 )
例2:的UTF-16:求和符号Σ(U + 2211)
Example 2: UTF-16: Summation symbol ∑ (U+2211)
C#:无论是Σ
或 u2211
变( 11
字节来自第一的)
C#: Either "∑"
or "u2211"
becomes (11
byte comes first)
ldstr bytearray (11 22 )
相关推荐
最新文章