I'm trying to solve this:
Type.GetType("Class1'[[Class2]]")
where Class1
and Class2
are in different assemblies.
I can parse the assemblies and find the Class1
type as well as the Class2
type, but how do I get to the Class1<Class2>
type?
if you can find the types all you need to is:
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 will be like having typeof(Class1<Class2>)
I think, it should look like this:
Type.GetType("Class1`1[Class2]");
Note: I changed the apostroph from ' to ` and added the number of generic arguments.
If this is not enough, try specifying the classes including namespace and assembly:
Type.GetType("Namespace1.Class1`1[[Namespace2.Class2, Assembly2]], Assembly1");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.