The class library I’m refactoring has a large number of events (over 50) each with its own Delegate, even though many have the same arguments. I starting switching them all over to use EventHandler and custom EventArgs but it is proving to be tedious and time consuming.
Is there an easier way to handle a situation like this, when you have a huge number of events?
You certainly don’t need your own delegate type – you can use
EventHandler<TEventArgs>whereTEventArgsis your specificEventArgssubclass.Refactoring a large mess is always time consuming and annoying. If you change to using method group conversions it can make it easier in the future though:
Then if the type of
SomeEventchanges, you can changeSomeMethodand the subscription will just work, without having to be changed again.Whether you need several different
EventArgssubtypes is a different matter – and impossible to say without knowing about your particular situation. If you need to pass a wide variety of pieces of information, it may indeed make sense.