问题
I want to create a generic list of the Type object.
I have ...
Type type = typeof(Foo);
object model = GetModel();
Now I want to create a new List<Foo>((Foo)model)
Is this possible in C#?
回答1:
Type listT = typeof(List<>).MakeGenericType(new[]{type});
object list = Activator.CreateInstance(listT);
来源:https://stackoverflow.com/questions/3712732/how-to-create-a-generic-list-with-a-dynamic-object-type