您好,我正在尝试使用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.0
在stloc
变量中
3.调用async
的构造函数,该结构占用上面的行
4。Command<Cell>
在stloc
中
5.致电command
6。ProcessAsync<Cell>