In C#, how can I construct generic type from generic definition and generic arguments like
var genericDefinition = typeof(List);
var genericArgument = typeof(string);
// How can I get the Type instance representing List<string> from the 2 variables above?
In my usecase, the generic argument is dynamically resolved. Is this possible in C#? Thanks in advance.
There's no such thing as
typeof(List)
. However,typeof(List<>)
works fine, and is the open generic type. Then you just use:and you should find that
concreteListType
istypeof(List<string>)
.