GetElementType
only gets the element-type for array, pointer and reference types.
When overridden in a derived class,
returns the Type of the object
encompassed or referred to by the
current array, pointer or reference
type
The reflection API doesn't "know" that List<T>
is a generic container and that the type-argument of one of its constructed types is representative of the type of the elements it contains.
Use the GetGenericArguments
method instead to get the type-arguments of the constructed type:
var elementType1 = typeof(List<A>).GetGenericArguments().Single();
List<T>
is a reference-type; a value (in general : expression) of such a type is a reference to an object. I'm guessing you just have a variable of a less-specific type (e.g.object
) that refers to aList<SomeT>
instance. That's just about assignment-compatibility, not boxing. It's a representation-preserving conversion; no boxing happens. – Chromite