Is it possible to subscribe to event subscriptions in C#?

c#, events

Solution

Similar to auto-implemented properties, events are auto-implemented by default as well.

You can expand the declaration of an `event` as follows:

public event MyEventHandler MyEvent
{
    add
    {
        ...
    }
    remove
    {
        ...
    }
}

See, for example, How to: Use a Dictionary to Store Event Instances (C# Programming Guide)

See Events get a little overhaul in C# 4, Part I: Locks for how auto-implemented events differ between C# 3 and C# 4.

Problem

If I have an event like this: ``` public delegate void MyEventHandler(object sender, EventArgs e); public event MyEventHandler MyEvent; ``` And adds an eventhandler like this: ``` MyEvent += MyEventHandlerMethod; ``` ... is it then possible to register this somehow? In other words - is it possible to have something like: ``` MyEvent.OnSubscribe += MySubscriptionHandler; ```

Original source