在不知道装配的情况下通过反射创建对象 [英] Create an object via reflection without knowing the assembly

查看:81
本文介绍了在不知道装配的情况下通过反射创建对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,

我有一些特殊的问题。我需要创建一个类的实例,但我不知道该类属于哪个程序集。我知道它来自app域中加载的程序集。我希望我可以通过以下方式使用它:

给定类路径,尝试从当前在应用程序域中加载的程序集之一创建对象。


任何方式这样做?


干杯,

Nelson

Hey all,
I have a bit of peculiar problem. I need to create an instance of a class, but I do not know which assembly that class belongs to. I do know it is from an assembly loaded within the app domain though. I was hoping I could have it work in the following way:
Given a classpath, attempt to create the object from one of the assemblies currently loaded in the app domain.

Any way of doing this?

Cheers,
Nelson

推荐答案

你不能通过类路径打开程序集吗?

或者你可以打开程序集集合并搜索它们里面的类吗?
Can''t you open an assembly by a class path?
Or maybe you can open up the collection of assemblies and search for the class inside them?


嗯有趣。我不知道该怎么做,或者我甚至可以做到这一点!

你知道这是怎么回事吗?我会看到我能找到的东西。

谢谢,

干杯
hmm interesting. I''m not sure how to do that, or that I could even do that!
Do you know how that works? I''ll see what I can find.
Thanks,
Cheers


你的课程路径是什么意思?

你是说你知道System.Net.Sockets.Socket吗?并且想要创建一个Socket实例,但是不确定要打开哪个dll /程序集?

你可以使用Type类来创建一个那样的实例
Well what do you mean by class path?
Are you saying you know "System.Net.Sockets.Socket" and want to create an instance of Socket, but aren''t sure what dll/assembly to open?
You can use the Type class to create an instace that way


这篇关于在不知道装配的情况下通过反射创建对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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