I have some generic interface linked one to each other.
public interface IA
{
int val { get; set; }
}
public interface IB<T> where T:IA
{
T a_val { get; set; }
}
public interface IC<T> where T : IB<IA>
{
T b_val { get; set; }
}
public class a:IA
{
public int val { get; set; }
}
public class b:IB<a>
{
public a a_val { get; set; }
}
public class c:IC<b>
{
public b b_val { get; set; }
}
For the last class c, i have an error:
The type 'b' cannot be used as type parameter 'T' in the generic type or method 'IC'. There is no implicit reference conversion from 'b' to 'IB'.
How can I properly use generic interfaces in this case ?
I don't know if it can be done easier (and a bit more clean), but this code compiles:
What's even more important, it don't let you do something like that:
Compiler throws following error:
And that is really cool feature, isn't it?