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.
精彩评论