I am consuming several different providers that implements the same Interface, instantiating and accessing them through an object factory.
I get the data from these different providers attaching to events. Each one of these providers have their own CustomEventArgs, which differs between providers…
Could you suggest an approach to manage the event (with the different eventArgs) in a “centralized” way? Something like casting Events? Just in case I want to do always the same behavior on events, like assing string properties to Label on IU.
-
Could I implement something like an intermediate class to listen the several event(with the different eventArgs) and then onEvent can raise a new MyEvent with MyOwnEventArgs that contains the sum of all the particular properties of the several CustomEventArgs from the providers? Is there an advantege on this?
-
Could I implement something like an intermediate class to listen the several event(with the different eventArgs) and then onEvent can raise a new MyEvent with MyOwnEventArgs that contains just one IDictionary property where each Item contains the name and value of all the particular properties of the several CustomEventArgs from the providers? Is there an advantege on this?
-
Is there any other way to read the “different” properties (different property name) from several CustomEventArgs in easy way?
Sounds like a good match for the adapter pattern to transform all the different event classes to your own event class.
If the providers follow the event pattern properly you’ll get the provider in the
sourceargument.So you can do something like this: