Use Type.MakeGenericType(type[])
:
Type elementType = GetElementType(); // get this type at runtime
Type listType = typeof(List<>);
Type combinedType = listType.MakeGenericType(elementType);
IList elements = (IList) Activator.CreateInstance(combinedType);
You have to use IList
to keep the result - because you don't know the actual type that will be used at runtime.
For generic types with more than one type parameter you would use something like Dictionary<,>
.
See also http://msdn.microsoft.com/en-us/library/system.type.makegenerictype.aspx