c# - Event triggered by event on base class, not derived class -


i have following structure:

class item static eventhandler boom  public virtual void handlestuff();  public void dostuff() trigger boom eventhandler handlestuff();   class childitem1 : item     override handlestuff() etc  class childitem2 : item     override handlestuff() etc 

so basicly when call childitem1.dostuff(); trigger on "item" class , execute handlestuff() on childitem1 class.

so here's problem, when subscribe event childitem1.boom trigger if call childitem2.dostuff(); triggers boom event on "item" class

so here's question, how can defined eventhandlers on base class, can subscribe on derived classes, without above issue?

this must because have event declared static.

if have non-static event declared on base class event invoked correctly expect.

the following program print derived apprpriately -

class program     {         static void main(string[] args)         {             var d = new derived();             d.boom += new eventhandler(handleboom);              d.triggerboom();              console.readline();         }          static void handleboom(object sender, eventargs e)         {             console.writeline(sender.gettype());         }     }      class base     {         public event eventhandler boom = null;          public void triggerboom()         {             if(boom != null)                 boom(this, eventargs.empty);         }     }      class derived : base     {     } 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -