I'm trying to extend the Process class a bit, to add access control of Process.Exited delegates and limit them to one. So far, I have this result:
public class ProcessWithData : Process
{
public EventHandler CurrentEventHandler { get; private set; }
public new bool EnableRaisingEvents = true;
private new EventHandler Exited;
public void SetHandler(EventHandler eventHandler)
{
if (CurrentEventHandler != null) Exited -= CurrentEventHandler;
CurrentEventHandler = eventHandler;
Exited += CurrentEventHandler;
}
}
However, the line
private new EventHandler Exited;
overwrites existing EventHandler of Process class being the base. Therefore
var proc = Process.Start("foo.exe");
ProcessWithData procwithdata = (ProcessWithData)proc;
should destroy Exited event handler upon cast.
How could I set private
modifier to it without redefining(and destroying) existing instance inside Process class?