The project I'm working on requires that I can fire an event every time an item is added to the list. To do this, I created my own List class, which inherits from List, and added the OnAdd event. I also want to return an element added as EventArgs, for which I added some 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 { get { return m_value; } } }
This is how I add a handler
clientList.OnAdd += new EventHandler<EventArgs<Client>>(clientList_OnAdd);
But in the OnAdd method:
private void clientList_OnAdd(object sender, EventArgs e) {
I can access only e.Equals, e.GetHashCode, e.GetType and e.ToString and not one of the members of the Client class.
source share