Why are delegation types derived from the MulticastDelegate class, why is it not obtained directly from the Delegate class?

I have a very simple question about delegate types. I matched the members of the Delegate and MulticastDelegate classes in the Object Browser, and I could not find the new additional member present in MulticastDelegate. I also noticed that the Delegate class has a virtual GetInvocationList method. Therefore, I assume that the Delegate class should be able to store references to several methods. If my assumption is correct, I wonder why non-custom delegate types directly derive from the Delegate class instead of the MulticastDelegate class. Not sure what I'm missing here. Please help me understand the difference.

+4
source share
1 answer

Basically, the separation of Delegate and MulticastDelegate occurs for historical reasons. Initially, there were delegates who could not be united, and those who could ... but this turned out to be not a useful difference. Apparently, this was only discovered when it was too late to break MulticastDelegate from the / CLR framework.

From CLR via C #, 3rd Edition:

The System.MulticastDelegate class is derived from System.Delegate, which itself is the result of System.Object. The reason two classes of delegates are historical and unsuccessful; in FCL, there must be only one delegate class. Unfortunately, you need to know both of these classes, because although all the delegate types you create have MulticastDelegate as the base class, you will sometimes manipulate your delegate types using methods defined by the Delegate class instead of the MulticastDelegate class. [...]

+9
source

Source: https://habr.com/ru/post/1337537/


All Articles