c# - How to do I return an item from a custom event handler -


a project i'm working on requires me able fire off event everytime item added list. achieve this, created custom list class inheriting list , added onadd event. want return item being added eventargs added more code (given below):

    public class clientlistobservable<client>:list<client>     {         public event eventhandler<eventargs<client>> onadd;          public void add(client item)         {             if (null != onadd)             {                 onadd(this, new eventargs<client>(item));             }              base.add(item);         }     }      public class eventargs<client> : eventargs     {         public eventargs(client value)         {             m_value = value;         }          private client m_value;          public client value         {             { return m_value; }         }     } 

this how add handler

clientlist.onadd += new eventhandler<eventargs<client>>(clientlist_onadd); 

but, in onadd method:

private void clientlist_onadd(object sender, eventargs e)         {             //want able access data members of client object added         } 

i can access e.equals, e.gethashcode, e.gettype , e.tostring, , none of members of client class.

change event args to:

public class clienteventargs : eventargs {     public clienteventargs(client value)     {         m_value = value;     }      private client m_value;      public client value     {         { return m_value; }     } } 

then:

    private void clientlist_onadd(object sender, clienteventargs e)     {         client client = e.value;     } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -