特殊对象类型的获取(Type.GetType)

一般,我们获取对象的类型有以下几种方法:

string vTypeName = "System.Int32";

Type vType = Type.GetType(vTypeName);

Type vType1 = typeof(int);

但是当动态加载一个程序集,并把这个程序集用到另外一个程序集中时,结果会有所出入。

Assembly vAssembly = Assembly.LoadFile(vDllFileName);

其中自定义了一个数据类型为[tempuri.org.LinearRing]

如果我们直接通过Type.GetType("tempuri.org.LinearRing"),将获取不到数据。

必须使用以下方法:

Type vType2 = vAssembly.GetType("tempuri.org.LinearRing");

string vTypeString = string.Format("System.Collections.Generic.List`1[[{0}]]", vType2 .AssemblyQualifiedName);//关键就是这句,包含了动态链接库信息,否则即使用vType2.FullName也获取不到类型信息
           
Type vType3 = pAssembly.GetType(vTypeString);

原文地址:https://www.cnblogs.com/si812cn/p/1384875.html