I have a problem with generics and new members. I wrote a generic class that works with an object of type ObjectA. ObjectB comes from ObjectA and hides several members of ObjectA. When I set the ObjectB type as a type parameter for a general class, I would expect that when I call any of the elements hidden by ObjectB, I would call an implementation of ObjectB. However, the CLR still calls hidden elements (an ObjectA implementation). This seems counterintuitive because I explicitly provided the ObjectB type to the generic class. Is this a problem with the generics themselves, or am I doing something wrong?
Edit: Unfortunately, I do not have access to the source code of ObjectA, and the member I want to override is not virtual. If I had access to the source code of ObjectA, I would make it a virtual member, but since I cannot do this, my only option for โredefiningโ a member is through a โnewโ keyword.
class GenericClass<T> where T : ObjectA { public void DoWork(T item) {
code>
source share