I want to do the following:
private static Dictionary<string, Delegate> handlers = new Dictionary<string, Delegate>();
private static void RecievedMessage(object sender, RecievedMessageEventArgs e) {
if(e == null || e.Message == null) return;
if(e.Message is RegisterMethodMessage) {
var registerMethodMsg = (RegisterMethodMessage)e.Message;
if(handlers.ContainsKey(registerMethodMsg.MethodName)) {
handlers[registerMethodMsg.MethodName] += registerMethodMsg.Handler; //Error
} else {
handlers.Add(registerMethodMsg.MethodName, registerMethodMsg.Handler);
}
}
}
A delegate added to the chain with the same key in the dictionary will have the same method signature.
If I were to substitute “Delegate” with a specific one like Action, the above code would work.
So my question is:
Is it possible to do the same without the substitution and without a lot of “hacking”?
Is there any reason you can’t do this: