delegate.Invoke 如何工作?

发布于 2024-11-16 02:48:08 字数 517 浏览 2 评论 0原文

如果我在代码中创建一个委托,如下所示:

delegate void dostuff (string o);

这会生成一个派生自 System.MulticastDelegate 的类,该类实现三个方法 - InvokeBeginInvokeEndInvoke

如果我查看 Invoke 的已编译 IL,我看到的只是:

.method public hidebysig newslot virtual 
        instance void  Invoke(string o) runtime managed
{
} // end of method dostuff::Invoke

该方法不包含任何代码。调用它确实有效 - 委托被调用,但我看不到它是如何做到的。

使得调用 Invoke 实际上调用 delegate 的巫毒从何而来?

If I create a delegate in my code like :

delegate void dostuff (string o);

This generates a class that derives from System.MulticastDelegate which implements three methods - Invoke, BeginInvoke and EndInvoke.

If I look at the compiled IL for Invoke all I see is :

.method public hidebysig newslot virtual 
        instance void  Invoke(string o) runtime managed
{
} // end of method dostuff::Invoke

The method contains no code. Calling it does work - the delegate gets invoked, but I can't see how it does it.

Where does the voodoo that makes calling Invoke actually call the delegate come from?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蒗幽 2024-11-23 02:48:08

伏都教可以在签名的末尾找到:运行时管理。请注意,您定义的所有托管类和方法都将被修饰为 cli 托管

运行时管理意味着运行时提供方法的预优化实现。

The voodoo can be found at the end of the signature: runtime managed. Notice that all of your managed classes and methods that you define will be decorated as cli managed.

runtime managed means that the runtime provides pre-optimized implementations of the methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文