I have a common interface ( MyInterface<T>) that is implemented by the class ChildAin the example below:
public interface MyInterface<T>
{
MyObj<T> GetObj();
}
class ChildA : MyInterface<ChildA>
{
MyObj<ChildA> GetObj() {
return new MyObj<ChildA>();
}
}
This works, but I need to make sure that it <T>always has the type of the implementing class, so in this case Tit should always have the type ChildA, because it is implemented ChildA.
Another option may be correct , for example:
class ChildB : MyInterface<ChildB> { ... }
But currently this incorrect implementation is also possible, while it should not be:
class ChildA : MyInterface<ChildB> { ... }
Is there any way to provide this?
source
share