我现在知道这个属性是个List<T>,在运行时我也能拿到这个T的名称,存在变量typeName中,那我应该怎么写代码创建一个List<typeName>的实例呢?你拿到T的名称后存到typeName中,在创建List<typeName> 实例,可以改下你的类,写个泛型类,用where约束你传过来的这个T,这样所有传过来的实体必须实例化, 例如, public class Class1 <T> where T : class, new() ,然后你就可以List<typeName> name=new List<typeName>()了 再根据PropertyInfo 对象 操作你的集合typeName
List<typeName>里面能写变量名?我怎么报错啊? string typeName = "EndToEndBlueprintRoot"; List<typeName> ll = new List<typeName>();
看看你类怎么定义的,根据你传过来的实体, 可以用type反射出它的实际类型,然后再创建它的集合实例
动态的阿,我的typeName只能动态取到,编译的时候肯定不知道阿。这种情况怎么办
目前只能对付一下,把所有这些可能的类都继承一个共同父类,程序里写死生成一个List<该父类>
真不知道你到底要干什么, public class Class1 <typeName> 这样定义 完全可以达到你的要求
string typeName = "EndToEndBlueprintRoot";
List<typeName> ll = new List<typeName>();