I want to create a generic List<> whose type is declared at runtime.
I can do the following, but since it's dynamic, I suspect there is a speed penalty. I'm writing a wrapper to an exotic database, so speed is critical.
List<dynamic> gdb = new List<dynamic>()
I read this post in dynamic generic types, but can't get it to work. Specifically, the object is not appearing as a List and hence has no add method.
Type ac;
switch (trail[dataPos].Type)
{
case GlobalsSubscriptTypes.Int32:
ac = typeof(System.Int32);
break;
case GlobalsSubscriptTypes.Int64:
ac = typeof(System.Int64);
break;
default:
ac = typeof(System.String);
break;
}
var genericListType = typeof(List<>);
var specificListType = genericListType.MakeGenericType(ac);
var gdb = Activator.CreateInstance(specificListType);
How do I get gdb to appear as one of the following:
List<System.Int32>
List<System.Int64>
List<System.String>