Weird generics compile error.
- by Jouke van der Maas
I have two classes, a base class and a child class. In the base class i define a generic virtual method:
protected virtual Bar Foo<T() where T : Bar {}
Then in my child class i try to do this:
protected override BarChild Foo() // BarChild inherits Bar
{
return base.Bar<T as BarChild()
}
Visual studio gives this weird error:
The type 'T' cannot be used as type parameter 'T' in the generic type or method 'Foo()'. There is no boxing conversion or type parameter conversion from 'T' to 'Bar'.
Repeating the where clause on the child's override also gives an error:
Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
So what am i doing wrong here?