In C# it is easy to create an open generic type, typeof(IEnumerable<>). Is there a way to create a type that contains an open generic? The following does not work: typeof(IEnumerable<IFoo<>>).
Is there a way to create a nested open generic type?
618 Views Asked by myermian At
2
There are 2 best solutions below
0
On
There's no way. These aren't generic but unbound types, these are special types, they can't be instantiated. An unbound generic type can only be used within a direct typeof-expression.
When you use typeof(IEnumerable<IFoo<>>) you aren't using the unbound type in the typeof expression but in the IEnumerable<T> expression.
Get the two unbound generic types involved, and then use one as the argument to making a generic type from the other: