Quote:Original post by capn_midnight
That only works if he has explict references to the EventArg types. If he is writing an event dispatching system that only ever handles argument sub-types through handles of the base EventArg type, then attempting to make a call like that will result in an ambiguous reference compile time error. The visitor pattern is necessary here.
This is the problem which I am encountering; I am using an interface IEventData, for example, to store event arguments. If I am using delegates (which is what .NET EventHandler boils down to, I believe), the signature would look like this:
public delegate bool EventHandler(IEventData eventData);
I would like to new event types to added (I am writing a close-source game library as part of the job description), so the coupling of events to their handlers has to be super-loose -- preferably, the user adding a new event type does not requires him to recompile the game library while at the same time, the library is supposed to have several pre-defined events.
Hence this topic.
Thanks a lot for code snippets so far, but how likely is the performance hit with reflection?
(BTW, don't worry about simple code fragments -- I am new to this reflection, where in C++ where RTTI is considered as the greatest sin in OOP or something, so simple code helps too :) )