Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the CLR know anything about Events?

It seems to me that Events are .NET manipulation on CLR. That is, there is no 'Event' concept nor command in IL, and the programming languages (such as C#) make use of delegates to achieve the behavior of events (which are just objects), in a way that from the CLR point of view there are no events, just a regular delegates mechanism. Is this true, or the CLR DOES have some special treatment for events?

like image 480
Shay___ Avatar asked Jan 20 '26 17:01

Shay___


1 Answers

The CLR certainly has awareness of events. They are present in the metadata of an assembly, the Reflection support built into the CLR exposes them. Its debugger interfaces expose event information to the debugger. The mapping of events declared in a [ComVisible] C# declaration to COM event sink interfaces is taken care of by the CLR Interop support built into the CLR.

But that perhaps can all be considered just infrastructure support. Turtles all the way down, the CLR isn't involved with subscribing and firing events directly, just the delegate. That's important, it needs to be fast. Otherwise core behavior of the CLR, it only ever gets involved when absolutely necessary.

like image 63
Hans Passant Avatar answered Jan 23 '26 07:01

Hans Passant