> Thankx for the answer.
Hi George,
I took a look an the IL of the following code:
delegate void MyEventHandler(object sender, EventArgs e);
The compiler generates a class derived from MulticastDelagate
consisting of these "runtime managed" (thus empty) methods:
.ctor
Invoke
BeginInvoke
EndInvoke
However, you *can* provide an CIL implementation too.
I changed "runtime managed" to "cil managed" and
it works:
.method public hidebysig virtual instance void
Invoke(object sender,
class [mscorlib]System.EventArgs e) cil managed
{
ldstr "test"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
So if you don't like the "runtime managed" black boxes
you still can roll your own delegate implementation, though
probably a bad idea.
bye
Rob
Mattias Sj?gren - 21 Oct 2004 16:20 GMT
Robert,
>However, you *can* provide an CIL implementation too.
>I changed "runtime managed" to "cil managed" and
>it works:
But is the result verifiable (test with PEVerify)? It certainly
violates section 13.6 in partition II of the ECMA specification.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Robert Jordan - 21 Oct 2004 16:45 GMT
Hi Mattias,
>>However, you *can* provide an CIL implementation too.
>>I changed "runtime managed" to "cil managed" and
>>it works:
>
> But is the result verifiable (test with PEVerify)? It certainly
> violates section 13.6 in partition II of the ECMA specification.
No, it doesn't pass the tests. Mono completely ignores the hack.
bye
Rob
George - 21 Oct 2004 17:24 GMT
Mattias,
> But is the result verifiable (test with PEVerify)? It certainly
> violates section 13.6 in partition II of the ECMA specification.
You are definitely right. Of course it violates the Spec.
Do you have any idea what is behind these runtime managed methods of a
delegate class?
Thank you. George
Hi Robert,
> When you define a new delegate type you don't need (or even cannot?)
it's "cannot" :))
> "runtime managed" methods are black boxes. you don't need to
> know what happens inside them, even when you're programming
> lowlevel IL.
exactly. this is the point of my question :) I want to know what is inside
these blackboxes (runtime managed). For example, I think that the .cctor sets
the two private fields "_target" and "_methodPtr". What else it does?
How it's the invocation with Invoke optimized?
All the best, George
Robert Jordan - 21 Oct 2004 12:40 GMT
Hi George,
>>When you define a new delegate type you don't need (or even cannot?)
>
> it's "cannot" :))
Ok :-)
>>"runtime managed" methods are black boxes. you don't need to
>>know what happens inside them, even when you're programming
[quoted text clipped - 3 lines]
> these blackboxes (runtime managed). For example, I think that the .cctor sets
> the two private fields "_target" and "_methodPtr". What else it does?
Hmm, Reflector is definitely able to disassemble the System.Delegate
.ctor. No magic inside apart from the InternalCalls :-)
You may take a look at Rotor (the shared source .NET from MS)
or at Mono (OpenSource).
Out of curiosity, what are you trying to achieve?
bye
Rob
George - 21 Oct 2004 12:53 GMT
Thank you Robert.
> Out of curiosity, what are you trying to achieve?
I want to (formally) model these delegates methods.
Bye. George
Mattias Sj?gren - 21 Oct 2004 16:31 GMT
George,
>I want to know what is inside these blackboxes (runtime managed).
Well that's implementation dependant and can vary from one CLI
implementation to another. For the CLR, see comdelegate.cpp/.h at
http://sharedsourcecli.sscli.net/source/browse/sharedsourcecli/clr/src/vm/
You can probably find similar code in the Mono source.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.