title: How can I save a reference to a generic type in .NET?
body: <p>I have a message queue that uses JSON to save messages, and a set of message receivers that are keyed by type. I have these methods to add and remove items from the queue:</p>
  
  <pre><code>public void AddToQueue&lt;T&gt;(T message)
  {
      var msg = JObject.FromObject(message);
  
      msg["_type"] = typeof(T).AssemblyQualifiedName;
  
      notificationQueue.PushBack(msg.ToString());
  }
  
  public void DispatchFromQueue()
  {
      var notification = notificationQueue.PopFront();
      if(notification != null)
      {
          var jobj = JObject.Parse(notification);
          var type = Type.GetType(jobj["_type"].Value&lt;string&gt;());
  
          var msg = JsonConvert.DeserializeObject(notification, type);
  
          // handle message
      }
  }
  </code></pre>
  
  <p>I believe these would work for ordinary types, like <code>string</code> or <code>MyCustomClass</code>. However, I believe it will fail for generic types, such as <code>MyGenericClass&lt;T&gt;</code>, or crazy cases like <code>ClassA&lt;ClassB&lt;ClassC&gt;&gt;</code>.</p>
  
  <p>Is there a standard way of getting/resolving type names that have the generic parameters built in? If not, how could I do this manually?</p>