title: Generic Methods Don't Call Methods of Type 'T'
body: <p>Suppose I have two classes:</p>
  
  <pre><code>class a
  {
      public void sayGoodbye() { Console.WriteLine("Tschüss"); }
      public virtual void sayHi() { Console.WriteLine("Servus"); }
  }
  
  class b : a
  {
      new public void sayGoodbye() { Console.WriteLine("Bye"); }
      override public void sayHi() { Console.WriteLine("Hi"); }
  }
  </code></pre>
  
  <p>If I call a generic method that requires type 'T' to be derived from class 'a':</p>
  
  <pre><code>void call&lt;T&gt;() where T : a
  </code></pre>
  
  <p>Then inside that method I call methods on an instance of type 'T' the method call are bound to type 'a', as if the instance was being cast as 'a':</p>
  
  <pre><code>call&lt;b&gt;();
  ...
  void call&lt;T&gt;() where T : a
  {
      T o = Activator.CreateInstance&lt;T&gt;();
      o.sayHi(); // writes "Hi" (virtual method)
      o.sayGoodbye(); // writes "Tschüss"
  }
  </code></pre>
  
  <p>By using reflection I am able to get the expected results:</p>
  
  <pre><code>call&lt;b&gt;();
  ...
  void call&lt;T&gt;() where T : a
  {
      T o = Activator.CreateInstance&lt;T&gt;();
      // Reflections works fine:
      typeof(T).GetMethod("sayHi").Invoke(o, null); // writes "Hi"
      typeof(T).GetMethod("sayGoodbye").Invoke(o, null); // writes "Bye"
  }
  </code></pre>
  
  <p>Also, by using an interface for class 'a' I get the expected results:</p>
  
  <pre><code>interface Ia
  {
      void sayGoodbye();
      void sayHi();
  }
  ...
  class a : Ia // 'a' implements 'Ia'
  ...
  call&lt;b&gt;();
  ...
  void call&lt;T&gt;() where T : Ia
  {
      T o = Activator.CreateInstance&lt;T&gt;();
      o.sayHi(); // writes "Hi"
      o.sayGoodbye(); // writes "Bye"
  }
  </code></pre>
  
  <p>The equivalent non-generic code also works fine:</p>
  
  <pre><code>call();
  ...
  void call()
  {
      b o = Activator.CreateInstance&lt;b&gt;();
      o.sayHi(); // writes "Hi"
      o.sayGoodbye(); // writes "Bye"
  }
  </code></pre>
  
  <p>Same thing if I change the generic constraint to 'b':</p>
  
  <pre><code>call&lt;b&gt;();
  ...
  void call&lt;T&gt;() where T : b
  {
      T o = Activator.CreateInstance&lt;T&gt;();
      o.sayHi(); // writes "Hi"
      o.sayGoodbye(); // writes "Bye"
  }
  </code></pre>
  
  <p>It seems that the compiler is generating method calls to the base class specified in the constraint, so I guess I understand what is happening, but this is not what I expected. Is this really the correct result?</p>