I have a C# generic:
public class Generic<TParameter> { ... }
It does not appear that I can use unbound types as type parameters. I get error CS1031: Type expected when I try the following:
var lGenericInstance = new Generic<List<>>();
How can I use an unbound type as a generic type parameter? Are there workarounds? My generic class is just using reflection so I can get a list of the provided type’s members as strings.
Update: My question about the unbound type has been answered, so I have followed up with a separate question that addresses my specific problem.
Try this:
Note that you can’t write
because the specification explicitly states:
(
Bar<>is not being used as a parameter to the typeof-expression here, rather, it’s a generic type parameter to the parameter to a typeof-expression.)However, it’s perfectly legal within the CLR, as the above using reflection shows.
But what are you trying to do? You can’t have instances of unbound types, so I don’t get it.