我正在编写一个特殊用途的迷你编译器,我经常查看反汇编的 CIL 来弄清楚如何做事。但如何将反汇编代码转换为 Reflection.Emit 调用通常并不明显。是否存在参考手册或任何其他信息来源来进行此翻译?
编辑:是的,将操作码映射到 ILGenerator 非常简单;我说的是所有其他的东西,比如 .directives 和属性。例如,您如何知道如何编写 Reflection.Emit 等价物Dictionary<TKey,TValue>
?
.class public auto ansi serializable beforefieldinit Dictionary<TKey, TValue>
extends System.Object
implements System.Collections.Generic.IDictionary`2<!TKey, !TValue>,
System.Collections.Generic.ICollection`1<valuetype
System.Collections.Generic.KeyValuePair`2<!TKey, !TValue>>,
...
{
.custom instance void System.Diagnostics.DebuggerDisplayAttribute::
.ctor(string) = { string('Count = {Count}') }
.method public hidebysig newslot virtual final instance bool TryGetValue
(!TKey key, [out] !TValue& 'value') cil managed
{
.maxstack 3
.locals init ([0] int32 num)
...
或者“参数”指令怎么样?
// public static void SayHello(string s = "Hello World!")
.method public hidebysig static void SayHello([opt] string s) cil managed
{
.param [1] = "Hello World!"