title: Pass class name to generic type
body: <p>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.</p>
  
  <p>I have a method that takes a generic type that has to be derived from <code>MessageBase</code> (<a href="https://docs.unity3d.com/ScriptReference/Networking.NetworkMessage.ReadMessage.html" rel="nofollow noreferrer">ReadMessage</a>).
  Now I have a list of class names that all inherit from MessageBase, like so:</p>
  
  <pre><code>public Dictionary&lt;int,string&gt; messageBaseNames = new Dictionary&lt;int,string&gt;();
  </code></pre>
  
  <p>Lets say my dictionary looks like this:</p>
  
  <pre><code>messageBaseNames = {
      { 1 : "MyMessageBase01" },
      { 2 : "MyMessageBase02" },
      { 3 : "AnotherMessageBase" }
  }
  </code></pre>
  
  <p>The <code>ReadMessage</code> method is usually used as follows:</p>
  
  <pre><code>public void ProcessMessageBase(NetworkMessage netMsg) {
      var msg = netMsg.ReadMessage&lt;MyMessageBase01&gt;();
  }
  </code></pre>
  
  <p>Is it possible to pass those string class representations to the <code>ReadMessage</code> generic type? The <code>netMsg</code> has an <code>short</code> value so that I know which string is the correct one.</p>
  
  <p>Just as an addition, this is the signature of <code>ReadMessage</code>: <code>public TMsg ReadMessage&lt;TMsg&gt; () where TMsg : MessageBase, new();</code></p>
  
  <p>And for clarification:</p>
  
  <p>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 <code>ReadMessage</code> function dynamic to accommodate different MessageBase types.</p>