Hi all, I have a situation which I feel should be workable, but it seems like I've indirected myself into a corner. Anyone familiar with C# might be able to tell me straight up what's possible or not:
I have an "event" class hierarchy:
public interface IEvent;
public class EventA : IEvent;
public class EventB : IEvent;
and a handler hierarchy:
abstract class EventHandler
{
List queue;
GoForIt()
{
foreach(IEvent e in queue)
ProcessEvent(e);
}
abstract void ProcessEvent(IEvent e);
}
class SpecificEventHandler : EventHandler
{
virtual void ProcessEvent(IEvent e)
{ /*catch all processing?*/ }
public void ProcessEvent(EventA e)
{ /*specific EventA processing*/ }
public void ProcessEvent(EventB e)
{ /*specific EventA processing*/ }
}
Now ideally I'd like to add events of various types to the handler's queue and have it figure out at runtime which overload to call based on the objects actual type. This does not do it, obviously - what happens is the compiler (i assume) decides it's dealing with IEvents, always, and calls ProcessEvent(IEvent) for all events in that loop there.
I get the feeling that I might be asking the impossible, but is there some way I can unbox the event dynamically and have it invoke the processevent method for its most derived type? I'd much rather use inheritance and polymorphism to do this than throw a whole bunch of explicit overloads in there or worse, giant conditional chains or switch statements...