Is it possible to do something like this in C#? Probably with Expressions. The EventHandlers are not members of a Control or any class that I own.
E.g.:
Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);
The EventHandler is a static reference that I don't own. How can I pass that type of statement to the following function?
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;
}
}