Skip to content

Recursive Type Inheritance

Type inheritance should not be recursive

What does this mean ?

Recursion is acceptable in methods, where you can break out of it. But with class types, you end up with code that will compile but not run if you try to instantiate the class.

What can happen ?

You will end up with code that will compile but not run if you try to instantiate the class.

Recommendation

Recursion in type inheritance should not be used.

Sample Code

Vulnerable :

class C1<T>
{
}
class C2<T> : C1<C2<C2<T>>> // Noncompliant
{
}

...
var c2 = new C2<int>();

References