究竟哪里是SomeDelegate.Invoke实施,它是如何"有线"到委托类 [英] Where exactly is SomeDelegate.Invoke implemented and how is it "wired" to the delegate classes
本文介绍了究竟哪里是SomeDelegate.Invoke实施,它是如何"有线"到委托类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在哪里完全相同(CLR源文件)可以找到实际执行 SomeDelegate.Invoke
方法?
Where exactly (CLR source file) can in find the actual implementation of the SomeDelegate.Invoke
method?
如何.NET运行时知道调用 SomeDelegate.Invoke
应导致调用该实现?请记住,在 SomeDelegate.Invoke
方法可以有任意数量的参数。
How does the .Net runtime knows that calling SomeDelegate.Invoke
should result in calling that implementation? Keep in mind that the SomeDelegate.Invoke
method can have any number of arguments.
推荐答案
所以,这里是巫术是如何工作的(从我发现掠入在源一个小时):
So, here is how the voodoo magic works (from what I found by glancing over the sources for an hour):
- 在某些时候,对于
SomeDelegate
类中的方法表是填充的,对调用
方法运行时失蹄。 - 的
PreStubWorker
(vm\prestub.cpp
)被调用,它调用DoPrestub
,要求MakeStubWorker
- 的
MakeStubWorker
认为,该方法是运行时实现的;(?为什么要问的方法表)(pMD-> IsEEImpl
),声称该方法表如下如委托和电话COMDelegate :: GetInvokeMethodStub
(vm\comdelegate.cp
p)来创建存根。 - 的
COMDelegate :: GetInvokeMethodStub
办法(vm\comdelegate.cpp
)电话COMDelegate :: TheDelegateInvokeStub
它调用EmitDelegateInvoke
和EmitMulticastInvoke
方法。 - 的
StubLinkerCPU :: EmitDelegateInvoke
和StubLinkerCPU :: EmitMulticastInvoke
方法在vm\i386\stublinkerx86.cpp
文件中实现(86)和vm\ppc\cgenppc.cpp
(用于PowerPC)。这些方法是很短,放出的调用
方法的具体装配/ CPU特定的实现。 - 来的方法实现的参考放置到
SomeDelegate
的方法表。
- At some time, the method table for the
SomeDelegate
class is populated and the runtime stumbles upon theInvoke
method. - The
PreStubWorker
(vm\prestub.cpp
) is called, which callsDoPrestub
, which callsMakeStubWorker
- The
MakeStubWorker
sees that the method is runtime-implemented (pMD->IsEEImpl
), asserts that the method table (why ask the method table?) looks like a delegate and callsCOMDelegate::GetInvokeMethodStub
(vm\comdelegate.cp
p) to create the stub. - The
COMDelegate::GetInvokeMethodStub
method (vm\comdelegate.cpp
) callsCOMDelegate::TheDelegateInvokeStub
which calls theEmitDelegateInvoke
andEmitMulticastInvoke
methods. - The
StubLinkerCPU::EmitDelegateInvoke
andStubLinkerCPU::EmitMulticastInvoke
methods are implemented in thevm\i386\stublinkerx86.cpp
file (for x86) andvm\ppc\cgenppc.cpp
(for PowerPC). These methods are quite short and emit the concrete assembly/CPU-specific implementations of theInvoke
methods. - The reference to the method implementation is put to the
SomeDelegate
's method table.
这篇关于究竟哪里是SomeDelegate.Invoke实施,它是如何"有线"到委托类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文