代表的构造函数和成员函数在哪里定义? [英] Where does delegates' constructors and member functions are defined?

查看:123
本文介绍了代表的构造函数和成员函数在哪里定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Reflector中看到 Action 代表时,我看到它有一个构造函数,如

When I was looking at the Action delegates in Reflector, I saw it has a constructor like

public Action(object @object, IntPtr method);

但是我找不到与其他成员函数一样的任何正文,如调用 BeginInvoke 等等。我只能看到它的定义。这些功能定义在哪里?是否定义在.net BCL之外?

But I could not find any body for the same along with other member functions like Invoke, BeginInvoke etc. I can only see the definitions for it. Where does these functions are defined? Are they defined outside of the .net BCLs?

推荐答案

基本上由CLR特别处理代表。编译器提供签名,但CLR知道如何处理它们。

Delegates are handled specially by the CLR, basically. The compiler provides the signatures, but the CLR knows what to do with them.

第8.9.3节 ECMA-335 分区我谈论这个:

Section 8.9.3 of ECMA-335 partition I talks about this:


代表是函数指针的面向对象的等价物。与函数指针不同,代理是
面向对象,类型安全和安全。代表是通过定义从基类型
System.Delegate派生的类创建的(请参阅分区IV)。每个委托类型应提供一个名为Invoke的方法,其中包含适当的
参数,并且委托的每个实例将其Invoke方法的调用转发到特定对象上的一个或多个兼容的
静态或实例方法。当
创建委托实例时,将选择它委派的对象和方法。

Delegates are the object-oriented equivalent of function pointers. Unlike function pointers, delegates are object-oriented, type-safe, and secure. Delegates are created by defining a class that derives from the base type System.Delegate (see Partition IV). Each delegate type shall provide a method named Invoke with appropriate parameters, and each instance of a delegate forwards calls to its Invoke method to one or more compatible static or instance methods on particular objects. The objects and methods to which it delegates are chosen when the delegate instance is created.

除了实例构造函数和Invoke方法之外,委托可以选择有两个额外的
方法:BeginInvoke和EndInvoke。这些用于异步调用。

In addition to an instance constructor and an Invoke method, delegates can optionally have two additional methods: BeginInvoke and EndInvoke. These are used for asynchronous calls.

虽然大多数情况下,代表似乎只是另一种用户定义的类,但是它们被紧密地限制在​​
中。这些方法的实现由VES提供,而不是用户代码。可以在委托类型上定义的唯一额外的
成员是静态或实例方法。

While, for the most part, delegates appear to be simply another kind of user-defined class, they are tightly controlled. The implementations of the methods are provided by the VES, not user code. The only additional members that can be defined on delegate types are static or instance methods.

(VES是虚拟执行系统; CLR是Microsoft的VES实现。)

(VES is the Virtual Execution System; the CLR is Microsoft's implementation of the VES.)

这篇关于代表的构造函数和成员函数在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆