The title might be little misleading, but I am not sure how to word it appropriately, so if anyone knows a better title, please edit.
I have a method that takes a generic type that has to be derived from MessageBase
(ReadMessage).
Now I have a list of class names that all inherit from MessageBase, like so:
public Dictionary<int,string> messageBaseNames = new Dictionary<int,string>();
Lets say my dictionary looks like this:
messageBaseNames = {
{ 1 : "MyMessageBase01" },
{ 2 : "MyMessageBase02" },
{ 3 : "AnotherMessageBase" }
}
The ReadMessage
method is usually used as follows:
public void ProcessMessageBase(NetworkMessage netMsg) {
var msg = netMsg.ReadMessage<MyMessageBase01>();
}
Is it possible to pass those string class representations to the ReadMessage
generic type? The netMsg
has an short
value so that I know which string is the correct one.
Just as an addition, this is the signature of ReadMessage
: public TMsg ReadMessage<TMsg> () where TMsg : MessageBase, new();
And for clarification:
I'm sending a bunch of different network messages that I want to a aggregate in a single function and distribute from that method. For that to work I need to make that ReadMessage
function dynamic to accommodate different MessageBase types.