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
Post a Comment