导入Mono程序集或.net程序集 [英] Import mono assembly or .net assembly

查看:85
本文介绍了导入Mono程序集或.net程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有2个DLL,1个仅用于Windows(使用Mono不支持的某些Windows特定DLL),1个用于Mono.这些DLL的方法原型都是相同的.
如果检测到Mono,则应导入LJUDMono,否则应导入LJUDWin.而且我想用DLLImport静态地做.

有什么建议?资源?

要动态地做到这一点,我发现本文通过DynamicMethod委托进行快速的后期绑定调用 [

Hi,

I have 2 DLLs, 1 is for Windows only (uses some Windows specific DLLs which are not supported by Mono) and 1 is for Mono. The method prototypes of those DLLs are all the same.
If Mono is detected the LJUDMono should be imported, else LJUDWin. And I''d like to do it statically with DLLImport.

Any suggestions? Resources?

To do it dynamically I found this article Fast late-bound invocation through DynamicMethod delegates[^].

推荐答案

为什么不只是将两个版本部署在不同的设置中,显然您会知道将在哪个平台上运行,因此只需打包文件即可.
Why don''t you just deploy the two versions in different setups, obviously you will know which platform you will be running on so just package your files accordingly.


您可以"不是静态地执行此操作,几乎是按照定义进行的(您所做的选择是运行时的选择).简单的解决方案是部署一个DLL,并使其适合该平台,如Mehdi所建议的那样.如果由于某种原因您不能执行此操作,则最好的方法可能是基于插件的插件,通过该插件,您可以选择在运行时加载哪个 assembly ,并让每个程序集都有一个实现ILJUDMethods的类.可以实例化. (如果您不知道如何使其工作,请在CP上搜索基于插件的体系结构;这里您只需要一个简单的AppDomain版本,因为您无需卸载或版本控制插件.)这样,您只有一个很慢的后期绑定(本质上就是将类型绑定到正确的程序集),之后的所有内容都可以通过接口(应在程序集中声明,应用程序和两个插件都可以访问该接口) ,取决于应用程序还是第四个单独的DLL,具体取决于这些类是否与应用程序相关).
You can''t do it statically, almost by definition (the choice you are making is a runtime one). The simple solution is to deploy one DLL, and make it the appropriate one for the platform, as Mehdi suggests. If for some reason you can''t do that, the best approach is probably a plugin based one whereby you choose which assembly to load at runtime, and have each assembly have a class which implements ILJUDMethods which you can instantiate. (Search CP for plugin based architectures if you aren''t aware of how to make it work; you should just need the simple, one AppDomain version here as you don''t need to unload or version-control the plugins.) That way, you only have one slow piece of late binding (essentially, binding the type to the right assembly), and everything after that can go through the interface (which should be declared in an assembly that the application and both plugins have access to do, either the application or a fourth separate DLL, depending on whether these classes are application dependent).


这篇关于导入Mono程序集或.net程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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