动态加载在C#中一个DLL [英] Dynamically loading a dll in C#

查看:208
本文介绍了动态加载在C#中一个DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口,用于编辑。编辑应该加载一个dll(我有完全控制),以响应用户的选择要知道如何直观地显示信息。
(它们是DLL的,作为一个用户不一定会想或需要每一个显示模式,并且还允许在不与主项目周围搞乱要添加新的)

I have a window to use for editing. The editor should load a dll (which I have full control of) in response to the user's selection to know how to display the information visually. (They're dll's, as a user will not necessarily want or need every single display model, and also allow new ones to be added without messing around with the main project)

他们都会简单地被储存在一个子目录(就目前而言)
我敢肯定,我可以枚举可用的dll,但我需要做2个事情,我不知道关于

They will all simply be stored in a subdirectory (for now anyway) I'm pretty sure I can enumerate the available dlls but I need to do 2 more things that I'm not sure on

1)一些方式来获得from\on DLL的元数据,这样我就可以建立可能的显示选项的列表...

1) Some way to get metadata from\on the dll, so I can build the lists of possible display selections...

2)将选定的dll,并卸载它必要的。

2) Load the selected dll, and unload it as necessary

任何建议,将不胜感激。

Any suggestions would be greatly appreciated.

推荐答案

发现了如何做到这一点很容易使用MEF,只需使用一个DirectoryCatalog指着你的插件目录,只要你有匹配[导出] S和[导入] S它的伟大工程。

Found out how to do this very easy using MEF, simply use a DirectoryCatalog pointed at your plugin dir, and as long as you have matching [Export]s and [Import]s it works great.

这篇关于动态加载在C#中一个DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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