title: Generics: Accessing New Members, Not Hidden Members
body: <p>I have run into a problem with generics and new members.  I wrote a generic class which operates on an object of type ObjectA.  ObjectB derives from ObjectA and hides a few of ObjectA's members.  When I supply the type of ObjectB as the type parameter to the generic class, I would expect that when I call any of the members hidden by ObjectB, I would be calling ObjectB's implementation.  However, the CLR still calls the hidden members (ObjectA's implementation).  This seems illogical because I explicitly provided the type of ObjectB to the generic class.  Is this a problem with generics themselves, or am I doing something wrong?</p>
  
  <p>Edit: Unfortunately, I do not have access to ObjectA's source code and the member I want to override is not virtual.  If I had access to ObjectA's source code, I would make the member virtual, but as I cannot do so, my only option for "overriding" the member is through the "new" keyword.</p>
  
  <p><code></p>
  
  <pre><code>class GenericClass&lt;T&gt; where T : ObjectA  
  {  
      public void DoWork(T item)  
      {  
          // When type parameter 'T' is ObjectB, should get ObjectB's implementation  
          item.Invoke();  
      }  
  }  
  
  class ObjectA  
  {
      public void Invoke()  
      {  
          // A's implementation...  
      }  
  }
  
  class ObjectB : ObjectA  
  {
      public new void Invoke()  
      {  
          // B's implementation...  
      }  
  }
  
  static void Main()  
  {  
      GenericClass&lt;ObjectB&gt; genericClass = new GenericClass&lt;ObjectB&gt;();  
      ObjectB objectB = new ObjectB();  
      genericClass.DoWork(objectB);  
  }
  </code></pre>
  
  <p></code></p>