了解以下代码段生成的IL

时间:2018-08-17 13:34:00

标签: c# reflection.emit ilgenerator

您好,我正在尝试使用Reflection.Emit动态生成方法,并且我不知道如何解释以下代码段:

C#(我要生成的内容)

 public Task<Cell> GetAsync(string key)
{
    IEnumerable<Component<Cell>> async = Core.ComponentEnumerator.Instance.GetAsync(key);
    Command<Cell> command = new Command<Cell>(async);
    return this.ProcessAsync<Cell>(command);
}
在发布模式下生成的

IL

method public hidebysig newslot virtual final instance class [System.Runtime]System.Threading.Tasks.Task`1<valuetype redius.Cell> GetAsync(string key) cil managed
{
    .maxstack 2
    .locals init (
        [0] class [System.Runtime]System.Collections.Generic.IEnumerable`1<valuetype redius.Component`1<valuetype redius.Cell>> enumerable,
        [1] valuetype redius.Command`1<valuetype redius.Cell> command)
    L_0000: call class redius.Core/ComponentEnumerator redius.Core/ComponentEnumerator::get_Instance()
    L_0005: ldarg.1 
    L_0006: callvirt instance class [System.Runtime]System.Collections.Generic.IEnumerable`1<valuetype redius.Component`1<valuetype redius.Cell>> redius.Core/ComponentEnumerator::GetAsync(string)
    L_000b: stloc.0 
    L_000c: ldloca.s command
    L_000e: ldloc.0 
    L_000f: call instance void redius.Command`1<valuetype redius.Cell>::.ctor(class [System.Runtime]System.Collections.Generic.IEnumerable`1<valuetype redius.Component`1<!0>>)
    L_0014: ldarg.0 
    L_0015: ldloc.1 
    L_0016: call instance class [System.Runtime]System.Threading.Tasks.Task`1<!!0> redius.OpsGenTemplate::ProcessAsync<valuetype redius.Cell>(valuetype redius.Command`1<!!0>)
    L_001b: ret 
}

有人可以向我解释以下几点吗?

1 第一条指令L_0000调用单例对象,但不将其值存储在任何地方。为什么它不使用ldarg.0,然后将此值转发到{{ 1}}构造函数?。
2 然后它调用Command<Cell> ...在我们的方法中只有该方法的1个参数时。

我一直期待一些事情:

1。加载参数0-ldarg.1
2。ldarg.0stloc变量中
3.调用async的构造函数,该结构占用上面的行
4。Command<Cell>stloc
5.致电command
6。ProcessAsync<Cell>

0 个答案:

没有答案