I have a problem; I’m using an external library where one particular event has its own custom eventargs; with no constructor. If I want to throw my own event using these eventargs, how can I?
I’ll give more detail if asked, but I’m not sure what exactly I should be giving. 🙂
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
EventArgsclass, then you shouldn’t be doing that. If you want to create your own event, then you should define a newdelegateand newEventArgstype (even if you were duplicating the class that is already defined in the library).There are good reasons for this:
EventArgstype they provide may no longer fit your needs.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
eventkeyword), 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?