如何将 IL 代码转换为 Mono.Cecil 命令?

How to convert IL code to Mono.Cecil commands?

我有以下 C# 代码

        this.Succeed = true;
        yield break;

在 IL 中(dnSpy 说):

        /* 0x0019AD95 16           */ IL_0000: ldc.i4.0
        /* 0x0019AD96 7380630006   */ IL_0001: newobj    instance void Class893/'<method_0>d__0'::.ctor(int32)
        /* 0x0019AD9B 25           */ IL_0006: dup
        /* 0x0019AD9C 02           */ IL_0007: ldarg.0
        /* 0x0019AD9D 7D54560004   */ IL_0008: stfld     class Class893 Class893/'<method_0>d__0'::'<>4__this'
        /* 0x0019ADA2 2A           */ IL_000D: ret

我想将其转换为 Mono.Cecil 指令,如下所示:

                    inst.Add(Instruction.Create(OpCodes.Ldc_I4_0));
                    inst.Add(Instruction.Create(OpCodes.Newobj));
                    inst.Add(Instruction.Create(OpCodes.Dup, 0x0019AD9B));
                    inst.Add(Instruction.Create(OpCodes.Ldarg_0));
                    inst.Add(Instruction.Create(OpCodes.Stfld, 0x0019AD9D));
                    inst.Add(Instruction.Create(OpCodes.Ret));

我该怎么做?

您可以使用 https://cecilifier.me (https://github.com/adrianoc/cecilifier) tool too help you learn how to translate C# to https://github.com/jbevain/cecil.

免责声明:我是该工具的开发者。