Suppose we have a nested generic class:
public class A {
public class B { }
}
Here, typeof(A
Apparently it can't be done in C#, you have to specify either both type parameters, or none.
And it doesn't seem to be supported by the CLR either, A
and A
refer to the same type:
Type t1 = typeof(A).GetNestedType("B`1");
Type t2 = typeof(A).GetNestedType("B`1");
// t1.Equals(t2) is true
The enclosing type of both types is A<>
(open generic type)
EDIT: further testing shows that typeof(A
is actually a generic type of arity 2, not a nested generic type of arity 1... typeof(A
returns an array with typeof(int)
and typeof(string)
. So typeof(A
would actually be equivalent to (A.B)
, which isn't supported (a generic type can't be partially closed)