Other answers suggest some ways (or hacks) how you could do that.
However, I'd say that if the author of the library didn't give you any way to create a new instance of their custom EventArgs
class, then you shouldn't be doing that. If you want to create your own event, then you should define a new delegate
and new EventArgs
type (even if you were duplicating the class that is already defined in the library).
There are good reasons for this:
- The library may change and the custom
EventArgs
type they provide may no longer fit your needs.
- The library may need to pass some special object or special ID to their
EventArgs
, so you may not be able to create the instance correctly.
Since you can only trigger an event from a class where it is defined, you're probably defining a new event in the class (using the event
keyword), so there is no real reason why you couldn't declare your own delegate. Or could you provide more details on how are you triggering the event?