How to get invocation list of an explicit event in C# -
i can define event following:
public event msg_callback event_pingmessage;
and invocation list of event following:
multicastdelegate event_delegate = (multicastdelegate)this.gettype().getfield(event_name, bindingflags.instance | bindingflags.nonpublic | bindingflags.getfield).getvalue(this); foreach (var handler in event_delegate.getinvocationlist()) { // use handler() here }
but, if define event_pingmessage
explicit event, like:
private msg_callback explicitevent; public event msg_callback event_pingmessage { add { explicitevent += value; int = 0; } remove { explicitevent -= value; } }
the multicastdelegate event_delegate = ...
line throws exception:
object reference not set instance of object.
how can .getinvocationlist()
explicit events?
you can use explicitevent.getinvocationlist()
. explicitevent
equivalent of field returned getfield(...)
call field-like event.
Comments
Post a Comment