获取新 AppDomain 中加载的程序集的类型
我正在使用此方法来创建我想要的对象。
对象的构造函数被成功调用。
现在,我想通过反射调用一个方法,但正如我发现的,我需要知道类型。当我执行诸如
Type type = Type.GetType(this.typeName);
type
之类的操作时,类型为 null。
所以,我需要知道的是:如何获取新 AppDomain 中加载的程序集的类型?
I'm using this method to create the object I want to.
The constructor of the object is successfully called.
Now, I want to call a method via reflection, but as I found out, I need to know the type. And when I do something like
Type type = Type.GetType(this.typeName);
type
is null.
So, what I need to know is: How do I get the type of an assembly loaded in a new AppDomain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用完整的程序集限定名称,因此可以使用
Type.GetType()
重新创建它。如果没有这个,将搜索执行程序集以查找并不总是包含您的类型的类型。
You need to use the full assembly qualified name, so you can recreate it with
Type.GetType()
Without this, the executing assembly will be searched for the type which doesn't always contain your type.
System.type类型对象本身就是一个对象,里面有一个类型对象指针成员,它的成员引用它自己,因为System.Type类型对象本身就是一个类型对象的“实例”。而System.Object的GetType方法返回指定对象的类型对象指针成员中存储的地址。换句话说,GetType 方法返回一个指向对象类型对象的指针,这就是您可以确定系统中任何对象的真实类型的方法。
Use System.Reflection.AssemblyName 是一个实用程序类,它为您提供程序集唯一标识的完整详细信息。使用该类的 GetType 方法可以了解加载的程序集的类型。
http://msdn.microsoft.com/en-us/library /system.object.gettype.aspx
System.type type object is an object by itself and has a type object pointer member in it, and it’s member refers to itself because the System.Type type object is itself an “instance” of a type object. And System.Object’s GetType method returns the address stored in the specified object’s type object pointer member. In other words the GetType method returns a pointer to an object’s type object, and this is how you can determine the true type of any object in the system.
Use System.Reflection.AssemblyName is an utility class which gives you complete details of an assembly's unique identity in full. Use GetType method of this Class to know the type of the Assembly loaded.
http://msdn.microsoft.com/en-us/library/system.object.gettype.aspx
这是我解决问题的方法:
我创建了一个接口,并使用 typeof(MyInterface) 来解决问题。
我希望这可以帮助你。
Here is how i solved the problem:
I created an interface, and used typeof(MyInterface) to work arround.
I hope this could help you.