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

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -