开发者

How does delegate.Invoke work?

开发者 https://www.devze.com 2023-03-13 21:52 出处:网络
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

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消