[英]Reflection, generics and multiple assemblies
我正在尝试解决这个问题:
Type.GetType("Class1'[[Class2]]")
其中Class1
和Class2
在不同的程序集中。
我可以解析程序集并找到Class1
类型和Class2
类型,但是如何获取Class1<Class2>
类型?
如果您可以找到所有类型,则只需:
Type class1Type = assembly1.GetType("Class1"); //or however you are able to get this type
Type class2Type = assembly2.GetType("Class2"); //or however you are able to get this type
Type genericType = class1Type.MakeGenericType(class2Type);
genericType就像具有typeof(Class1<Class2>)
我认为应该看起来像这样:
Type.GetType("Class1`1[Class2]");
注意:我将撇号从'更改为`,并添加了通用参数的数量。
如果这还不够,请尝试指定包括名称空间和程序集的类:
Type.GetType("Namespace1.Class1`1[[Namespace2.Class2, Assembly2]], Assembly1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.