I'm trying to cleanup some duplicate code blocks by introducing a generic function. But I don't manage to do so and I have the feeling that my class inheritance structure is becoming messier than the code I'm trying to clean...
Here's an abstract overview of the classes involved:
interfaces:
interface Ia
interface Ib : Ia
interface Ic : Ib
classes:
class Ca<T> where T : Ia
class Cb<T> : Ca<T> where T : Ia
class Cc : Cb<Ic>
function:
void F<T>(T t) where T : Ca<Ib>
invalid function call:
F<Cc>(my_c);
error:
The type 'Cc' cannot be used as type parameter 'T' in the generic type or method 'F<T>(T)'. There is no implicit reference conversion from 'Cc' to 'Ca<Ib>'.
I guessed the word 'implicit' in the error my refer to the fact that there is no where T : Ib in the class definitions. So I added another class
class Cb2<T> : Cb<T> where T : Ib
and made Cc inherit from Cb2 instead of Cb. But this resulted in the same error.
Can anyone explain why this is restricted, and how I could solve it?
Thanks!