I have a Dictionary to map a certain type to a certain generic object for that type. For example:
typeof(LoginMessage) maps to MessageProcessor
public delegate void MessageProcessor(T msg) where T : IExternalizable;
virtual public void OnRecivedMessage(IExternalizable msg)
{
Type type = msg.GetType();
ArrayList list = processors.Get(type);
if (list != null)
{
object[] args = new object[]{msg};
for (int i = list.Count - 1; i >= 0; --i)
{
Delegate e = (Delegate)list[i];
e.Method.Invoke(e.Target, args);
}
}
}