如何将List转换为指定的List <t>,其中T来自CodeDom </t>

时间:2014-05-19 04:12:20

标签: c# dynamic codedom

Assembly assembly = cr.CompiledAssembly;
object instance = assembly.CreateInstance("Models.Test", true, BindingFlags.Default, null, null, null, null);
Type instType = instance.GetType();
instType.GetProperty("Code").SetValue(instance, "Code_value", null);
instType.GetProperty("Name").SetValue(instance, "Name_value", null);
instType.GetProperty("Address").SetValue(instance, "Address_value", null);

var listType = typeof(List<>);
var genericListType = listType.MakeGenericType(instType);
var instGenericListType = (IList)Activator.CreateInstance(genericListType);

instGenericListType.Add(instance);

我有IList,现在我要转换List<Models.Test>,我该怎么做?当我致电MakeGenericType

时,我是否有指定类型的方式?

0 个答案:

没有答案