How to write a custom event handler adder method in C# -
i have defined foo
class , used in bar
class, event handler:
public class bar { public bar() { foo foo = new foo(); foo.my_custom_event += my_event_handler; } public void my_event_handler() { // work here } }
and works perfectly. need define method in foo
class fired when add event handler my_custom_event
, like:
public class foo { ... public/private void my_event_handler_adder(target_function) { functions_that_are_fired_on_my_custom_event.append(target_function); } }
is there way define such adder method?
class foo { private eventhandler explicitevent; public event eventhandler explicitevent { add { explicitevent += value; fireneededmethodhere(); } remove { explicitevent -= value; } } }
Comments
Post a Comment