C#反射创建List实体

string className = "Person";
string namespaceStr = "ConsoleApplication1";
var model = Assembly.GetExecutingAssembly().CreateInstance(string.Join(".", new object[] { namespaceStr, className }));
var modelList = Activator.CreateInstance(typeof(List<>).MakeGenericType(new Type[] { model.GetType() }));
var addMethod = modelList.GetType().GetMethod("Add");
addMethod.Invoke(modelList, new object[] { model });

原文地址:https://www.cnblogs.com/lovewl2/p/6582347.html