Reflection和Type.GetType [英] Reflection and Type.GetType

查看:84
本文介绍了Reflection和Type.GetType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用Type.GetType返回一个类型'是在一个

从磁盘加载的程序集?


我很遗憾_have_使用Type.GetType,因为它在框架代码中我不能

更改。


目前,我正在加载从磁盘组装(工作正常)

并将其添加到当前的AppDomain(只是为了安全起见),

但即使我这样做,输入.GetType无法找到它。


有什么建议吗?


Andy D

Is there any way to use Type.GetType to return a type that''s in an
Assembly loaded from disk?

I sadly _have_ to use Type.GetType, as it''s in framework code I can''t
change.

At the moment, I''m loading the Assembly from disk (which works fine)
and adding it to the current AppDomain (just to be on the safe side),
but even when I do that, Type.GetType fails to find it.

Any suggestions?

Andy D

推荐答案

您是否将完全限定名称传递给Type.GetType(" MyNameSpace.MyClass")?

即Namespace.Class


Kalpesh
Are you passing in the fully qualified name to Type.GetType("MyNameSpace.MyClass") ?
i.e Namespace.Class

Kalpesh


>您是否将完全限定名称传递给Type.GetType(" MyNameSpace.MyClass")?
>Are you passing in the fully qualified name to Type.GetType("MyNameSpace.MyClass") ?
ie Namespace.Class
i.e Namespace.Class




你必须包含程序集名称以及获得真正的FQ类型

名称。

Mattias


-

Mattias Sj?gren [C#MVP] mattias @ mvps.org
http:// www .msjogren.net / dotnet / | http://www.dotnetinterop.com

请回复到新闻组。



You have to include the assembly name as well to get a truly FQ type
name.
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Andrew Ducker< an **** @ ducker.org.uk>写道:
Andrew Ducker <an****@ducker.org.uk> wrote:
有没有办法使用Type.GetType返回从磁盘加载的程序集中的类型?

我很遗憾_have_到使用Type.GetType,因为它在框架代码中我无法改变。

目前,我正在从磁盘加载程序集(工作正常)
并将其添加到当前的AppDomain(只是为了安全起见),
但即使我这样做,Type.GetType也找不到它。

任何建议?
Is there any way to use Type.GetType to return a type that''s in an
Assembly loaded from disk?

I sadly _have_ to use Type.GetType, as it''s in framework code I can''t
change.

At the moment, I''m loading the Assembly from disk (which works fine)
and adding it to the current AppDomain (just to be on the safe side),
but even when I do that, Type.GetType fails to find it.

Any suggestions?




是 - 在对Type.GetType的调用中指定程序集名称。对于

实例:


使用系统;


公共类测试

{

static void Main()

{

Type type = Type.GetType(" System.Data.SqlClient.SqlCommand," +

" System.Data," +

" Version = 1.0.5000.0," +

" Culture = neutral, " +

" PublicKeyToken = b77a5c561934e089");

Console.WriteLine(type);

}

}

-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复群组,请不要邮寄我也是



Yes - specify the assembly name in the call to Type.GetType. For
instance:

using System;

public class Test
{
static void Main()
{
Type type = Type.GetType("System.Data.SqlClient.SqlCommand, " +
"System.Data, "+
"Version=1.0.5000.0, "+
"Culture=neutral, "+
"PublicKeyToken=b77a5c561934e089");
Console.WriteLine (type);
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


这篇关于Reflection和Type.GetType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆