I have a Dictionary to map a certain type to a certain generic object for that type. For example:
typeof(LoginMessage) maps to MessageProcessor
This is simply not allowed:
Type key = message.GetType();
MessageProcessor processor = messageProcessors[key] as MessageProcessor;
You cannot get a generic type as a variable value.
You'd have to do a switch or something:
Type key = message.GetType();
if (key == typeof(Foo))
{
MessageProcessor processor = (MessageProcessor)messageProcessors[key];
// Do stuff with processor
}
else if (key == typeof(Bar))
{
MessageProcessor processor = (MessageProcessor)messageProcessors[key];
// Do stuff with processor
}
...