mercredi 19 août 2015

Why is the base type of an open generic type not open?

Consider a piece of the code below:

public class A<T> { }

public class B<T> : A<T> { }

In such case:

var a = typeof(A<>).GenericTypeArguments.Length;

a has the value 0, which is not surprising. This, however, is somehow unexpected for me:

var b = typeof(B<>).BaseType.GenericTypeArguments.Length;

where b has the value 1. So it is closed using a non-existing type of name "T" and only doing GetGenericArguments on it makes it open again. Why is that?





Aucun commentaire:

Enregistrer un commentaire