Gae*_*eur 107 c# compiler-construction debugging
如果您曾经使用过Reflector,您可能会注意到C#编译器会生成类型,方法,字段和局部变量,这些变量值得调试器"特殊"显示.例如,以"CS $"开头的局部变量不会显示给用户.匿名方法的闭包类型,自动属性的后备字段等还有其他特殊的命名约定.
我的问题:在哪里可以了解这些命名约定?有谁知道一些文件?
我的目标是使PostSharp 2.0使用相同的约定.
Eri*_*ert 204
这些是编译器的未记录的实现细节,并且可能随时更改.(更新:请参阅GeneratedNames.cs
C#来源了解当前的详细信息;以下描述有些过时.)
但是,既然我是一个好人,这里有一些细节:
如果您有一个优化程序删除的未使用的局部变量,我们会将调试信息发送到PDB中.我们将后缀粘贴__Deleted$
到这些变量上,以便调试器知道它们是源代码但不在二进制文件中表示.
由编译器分配的临时变量槽的名称为CS $ X $ Y,其中X是"临时类型",Y是到目前为止分配的临时数.临时种类是:
0 --> short lived temporaries
1 --> return value temporaries
2 --> temporaries generated for lock statements
3 --> temporaries generated for using statements
4 --> durable temporaries
5 --> the result of get enumerator in a foreach
6 --> the array storage in a foreach
7 --> the array index storage in a foreach.
Run Code Online (Sandbox Code Playgroud)
8到264之间的临时类型是多维数组的附加数组索引存储.
264以上的临时种类用于涉及修复字符串的固定语句的临时种类.
为以下内容生成特殊编译器生成的名称:
1 --> the iterator state ("state")
2 --> the value of current in an iterator ("current")
3 --> a saved parameter in an iterator
4 --> a hoisted 'this' in an iterator ("this")
5 --> a hoisted local in an iterator
6 --> the hoisted locals from an outer scope
7 --> a hoisted wrapped value ("wrap")
8 --> the closure class instance ("locals")
9 --> the cached delegate instance ("CachedAnonymousMethodDelegate")
a --> the iterator instance ("iterator")
b --> an anonymous method
c --> anonymous method closure class ("DisplayClass")
d --> iterator class
e --> fixed buffer struct ("FixedBuffer")
f --> anonymous type ("AnonymousType")
g --> initializer local ("initLocal")
h --> query expression temporary ("TransparentIdentifier")
i --> anonymous type field ("Field")
j --> anonymous type type parameter ("TPar")
k --> auto prop field ("BackingField")
l --> iterator thread id
m --> iterator finally ("Finally")
n --> fabricated method ("FabricatedMethod")
o --> dynamic container class ("SiteContainer")
p --> dynamic call site ("Site")
q --> dynamic delegate ("SiteDelegate")
r --> com ref call local ("ComRefCallLocal")
s --> lock taken local ("LockTaken")
Run Code Online (Sandbox Code Playgroud)
生成魔法名称的模式是:P<N>C__SI
其中: