"Fao, Sean" <(E-Mail Removed)-WANT-NO-SPAM> wrote in message
news:(E-Mail Removed)...
> If you look at a delegate as a pointer to a function (or in the case of
> C#, a reference to a method) everything else should make sense.
Actually, although P/Invoke automatically compiles delegates into function
pointers, that may not be the internal representation of a delegate. By
reading the discussion of delegates and constrained execution regions
(
http://msdn.microsoft.com/msdnmag/is...0/Reliability/), it seems that
delegates are not pre-jitted.
So the original poster was very nearly correct. The runtime maintains a
list of all loaded methods (irregardless of namespace, and including all
assemblies). The delegate constructor checks the compatibility of the given
method (the C# compiler will do this in advance where possible), and stores
the metadata handle. Invoking the delegate causes the runtime to lookup the
method by its handle, JIT the MSIL if that hasn't been done yet, and then
run the native code generated by the JIT.
But nowhere does the runtime maintain a list of "methods compatible with
delegate type XYZ". It has a list of all methods, and enforces a subtype
constraint during compile or delegate construction (for construction by
reflection, see Delegate.CreateDelegate).
>
> Hope that helps,
>
> --
> Sean