Automatically unsubscribe an event
- by Cat
Is it possible to do something like this in C#? Probably with Expressions.
private void RegisterEvent(EventHandler handler, Action<EventArgs> action)
{
handler += action;
m_toUnsubscribe.Add(handler, action);
}
... in Dispose()
{
foreach(var pair in m_toUnsubscribe)
{
pair.handler -= pair.action;
}
}