M
Michael Kennedy [UB]
Hi,
I have a situation where I need to clear the event sinks from an event
inside a custom class. But I don't know which methods signed up for that
event.
Consider the following example:
public class B
{
public event System.EventHandler DoneIt;
// ....
}
B b = new B();
b.DoneIt += X;
Now eventually suppose I want to "reset" b so that DoneIt == null but I
don't want to completely generate a new object, just the event sinks.
Typically this is done using
b.DoneIt -= X;
But in this case we don't know what X is. B is in a class library and we
have no control or knowedge of what the consumers of that class might do
with DoneIt.
My question is: Is there a way to have b force DoneIt to be null without
explicitly knowing the right hand side of += since it happened outside our
code?
Thanks in advance,
Michael
ps In case you haven't tried this before: b.DoneIt = null; does not compile.
I have a situation where I need to clear the event sinks from an event
inside a custom class. But I don't know which methods signed up for that
event.
Consider the following example:
public class B
{
public event System.EventHandler DoneIt;
// ....
}
B b = new B();
b.DoneIt += X;
Now eventually suppose I want to "reset" b so that DoneIt == null but I
don't want to completely generate a new object, just the event sinks.
Typically this is done using
b.DoneIt -= X;
But in this case we don't know what X is. B is in a class library and we
have no control or knowedge of what the consumers of that class might do
with DoneIt.
My question is: Is there a way to have b force DoneIt to be null without
explicitly knowing the right hand side of += since it happened outside our
code?
Thanks in advance,
Michael
ps In case you haven't tried this before: b.DoneIt = null; does not compile.