title: Multi-Level type inference in C#
body: <p>I am wondering if there is a specific reason why the C# compiler does not seem to support two-level type inference on generics.</p>
  
  <p>See the following code sample:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          var instance = new GenericClass&lt;object&gt;();
          Test&lt;GenericClass&lt;object&gt;, object&gt;(instance); // works
          Test(instance); // Type arguments cannot be inferred
      }
  
      static void Test&lt;TGenericClass, T&gt;(TGenericClass obj) 
        where TGenericClass : IGenericClass&lt;T&gt;
      {
  
      }
  }
  
  public class GenericClass&lt;T&gt; : IGenericClass&lt;T&gt;
  {
      public T Prop { get; set; }
  }
  
  public interface IGenericClass&lt;T&gt;
  {
      T Prop { get; set; }
  }
  </code></pre>
  
  <p>The compiler cannot infer that an object of type <code>GenericClass&lt;object&gt;</code> respects the type constraints, instead I have to specify the types manually. Is there a reason why the compiler does not support inference across multiple levels? How do you usually deal with it?</p>
  
  <p>EDIT: Assume <code>TGenericClass</code> has to be generic.</p>