I have two classes, a base class and a child class. In the base class i define a generic virtual method:
protected virtual ReturnType Create<T>() where T : ReturnType {}
Then in my child class i try to do this:
protected override ReturnTypeChild Create<T>() // ReturnTypeChild inherits ReturnType { return base.Create<T> as ReturnTypeChild; }
Visual studio gives this weird error:
The type 'T' cannot be used as type parameter 'T' in the generic type or method 'Create()'. There is no boxing conversion or type parameter conversion from 'T' to 'ReturnType'.
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?