I have several business objects in my app that all have a static "ObjectAction" event. This event gets fired when an object is added, edited, or deleted, and the eventargs contain the type of action that took place.
Now, I have also built a ListBox<T> which will make a BusinessObject (T) specific listbox.
The reason I have made the ObjectAction event static, is so that my listbox<T> can subscribe to it, and say add the business object to it's list when the event fires with e.Action == Added.
Right now, I wrap ObjectListBox<T> to make my final control (i.e. CompanyListBox : ObjectListBox<Company>), and I can subscribe to the static events in each wrapped control. But what I would really like to do is create a IBusinessObject interface that defines the ObjectAction event in it, then have each of my business objects implements this interface. This way, I can move my event subscription to the gereric list box, rather than doing it for each wrapped one.
Now that I have completely danced around that explanation....I want to end up with this...
public class BusinessObject : IBusinessObject
{
// IBusinessObject member
public static event BusinessObjectActionEventHandler Action;
blah, blah, blah
}
public class ObjectListBox<T> : ListBox where T : IBusinessObject
{
public ObjectListBox()
{
T.Action += new BusinessObjectActionEventHandler(EventHandler);
}
}
private EventHandler()
{
blah, blah
}
Does this make sense, and anyway to accomplish this
TIA