[英]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.