博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

Posted on 2009-02-05 21:10  懒人ABC  阅读(1852)  评论(0编辑  收藏  举报

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

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);