Having the following definition:
public class Generic<T>
{
public class Nested { }
}
And given that ECMA ref §25.1 states:
Any class nested inside a generic class declaration or a generic struct declaration (§25.2) is itself a generic class declaration, since type parameters for the containing type shall be supplied to create a constructed type.
I understand that Nested requires the type parameter in order to be instantiated.
I can obtain the generic Type with typeof:
var type = typeof(Generic<>.Nested);
// type.FullName: Namespace.Generic`1+Nested
Is there any way I can use it as a type parameter for a generic method such as the following?
var tmp = Enumerable.Empty<Generic<>.Nested>();
// Error: Unexpected use of an unbound generic
As stated before, from the ECMA specification I understand that all the type parameters must be satisfied before instancing but no objects are being created here. Furthermore, the Nested class does not make use of the type parameters in any way: I simply would like to define it nested for code organization purposes.
Nesteddoesn't utilizeTand that you're currently prototyping with an empty sequence do not appear to be relevant. For a fully constructible type for the sequence, you'll need to supply the type parameter.var tmp = Enumerable.Empty<Generic<>.Nested>();outside of the parent class? Otherwisevar tmp = Enumerable.Empty<Nested>();should work.