MultiCastDelegate

  • Thread starter Thread starter MB
  • Start date Start date
M

MB

Hi,

I got following :

' This delegate is declared as a void, so the compiler automatically
' generates a new class, named CheckAndPrintDelegate, that inherits from
' System.MulticastDelegate

from :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemMulticastDelegateClassTopic.asp

But how do you inherit from a multicast delegate ?
When I try this, I get following error: cannot inherit from special class
'System.MulticastDelegate'

Don't understand that multicast thingy all to good :)

thanks
 
Hi,

Delegates are internally classes which the compiler generates. These
classes derive from System.Delegate (if there the delegate has a return
value) or System.MulticastDelegate (if there are no return values).

You are not supposed to use these classes in your code.

Let me know if you need more assistance.

HTH,
Rakesh Rajan
 
delegates *always* derive from System.MulticastDelegate whether they have a return type or not. When you fire a delegate that has a return type and has multiple targets you only see the result from the last invocation. To see all the results you have to process the calls manually via GetInvocationList()

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,

Delegates are internally classes which the compiler generates. These
classes derive from System.Delegate (if there the delegate has a return
value) or System.MulticastDelegate (if there are no return values).

You are not supposed to use these classes in your code.

Let me know if you need more assistance.

HTH,
Rakesh Rajan
 
There were two types of delegates in beta 1 of 1.0 but then they realised a single target delegate was really only a multicast delegate with only one entry in its invocation list and so simplified the model to what you see today.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi Richard,

I agree that this is indeed the case as is evident in the IL.

But ideally, I don't feel this should be the case. I feel that it should be
the way as described in the MSDN page @: http://msdn.microsoft.com/library/d...ml/frlrfSystemMulticastDelegateClassTopic.asp

But for some reason, it seems it is not as is documented.

HTH,
Rakesh Rajan
 
Hi,

Thanks Richard, for the extra info.

Hmm...so shouldn't they be updating the documentation?

Regards,
Rakesh Rajan
 
Hi,

It's in the source code comments they are referring to this.

Quoting it:
' This delegate is declared as a void, so the compiler automatically
' generates a new class, named CheckAndPrintDelegate, that inherits from
' System.MulticastDelegate.
' If this delegate were declared with a Boolean return value, it
' would inherit from System.Delegate and be a singlecast delegate.

Regards,
Rakesh Rajan
 
Yep - that definitely needs changing - good spot

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,

It's in the source code comments they are referring to this.

Quoting it:
' This delegate is declared as a void, so the compiler automatically
' generates a new class, named CheckAndPrintDelegate, that inherits from
' System.MulticastDelegate.
' If this delegate were declared with a Boolean return value, it
' would inherit from System.Delegate and be a singlecast delegate.

Regards,
Rakesh Rajan
 
Back
Top