title: Getting type of a type parameter constrained class in C# 3.5
body: <p>I'm trying to get the type of a custom class to which I don't have access to editing and it has a  parameter type constraint on its declaration. Just like this:</p>
  
  <pre><code>public class GenericItemCollection&lt;T&gt; where T : System.IEquatable&lt;T&gt;
  {
      public GenericItemCollection();
      public GenericItemCollection(string json);
  
      public int Count { get; }
      public List&lt;T&gt; Created { get; }
      public List&lt;T&gt; Current { get; }
      public List&lt;T&gt; Deleted { get; }
      public List&lt;T&gt; Original { get; }
      public List&lt;T&gt; Updated { get; }
  
      public void AcceptChanges();
      public void AddItem(T item);
      public void BindItem(T item);
      public void DeleteItem(T item);
      public void UpdateItem(T item);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So what I want is the type GenericItemCollection when T is actually something. Ie:</p>
  
  <pre><code>private void MyMethod&lt;T&gt;(GenericItemCollection&lt;T&gt; genericList){
      Type listType = typeof(GenericItemCollection&lt;typeof(T)&gt;);
      //...
  }
  </code></pre>
  
  <p>which will be called as such:</p>
  
  <pre><code>MyMethod&lt;Foo&gt;(fooGenericList);
  MyMethod&lt;Bar&gt;(barGenericList);
  </code></pre>
  
  <p>In that case, I want listType to be </p>
  
  <pre><code>GenericItemCollection&lt;Foo&gt; 
  </code></pre>
  
  <p>and </p>
  
  <pre><code>GenericItemCollection&lt;Bar&gt; 
  </code></pre>
  
  <p>I know typeof(T) won't exist before runtime but it should return a Type regardless but VS just says "Type expected" on </p>
  
  <pre><code>GenericItemCollection&lt;typeof(T)&gt; 
  </code></pre>
  
  <p>I'm not all that proficient using Generics, so I'm obviously missing something and I'd like you guys to point out what that is. Many thanks.</p>