动态生成相同的装配间隙模块 [英] Dynamically Generate Modules in same Assembly Space

查看:85
本文介绍了动态生成相同的装配间隙模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑我有一个程序运行,应采取以下
应该从一个文本文件中读取一些代码,应该在自己的装配间隙执行它,使正在执行的新的代码可以访问的所有组件代码已经在运行。
这怎么可能?请帮助。

Consider I have a program running, which should do the following- Should read some code from a text file and should execute it in its own Assembly space so that the new code being executed can access all components of the code already running. How is that possible?? Help please.

推荐答案

根据大会的空间,你的意思的AppDomain?

By assembly space, do you mean AppDomain?

您可能想要看的 IronPython的。 。作为脚本语言它更适合用于被动态地添加到在运行时该程序

You might want to look at IronPython. As a scripting language it is better suited for being dynamically added to the program at runtime.

否则:

您可以通过 Microsoft.CSharp.CSharpCodeProvider 的坐在System.dll中。

You have access to the C# (and VB.NET) compiler via the Microsoft.CSharp.CSharpCodeProvider sitting in System.dll.

您可以用它来编译文本文件到一个单独的DLL(可能在内存中)。请确保您添加当前执行的程序集作为参考而编制。此后,您可以

You can use it to compile that text file into a separate dll (possibly in-memory). Make sure that you add your currently executing assembly as a reference while compiling. Then you can either


  • 装载组件插入到当前执行的AppDomain。通过这种方式,它可以访问应用程序中的所有对象。然而,你的无法卸载的重新编码。你必须卸载整个AppDomain中(即您的应用程序)

  • 组装加载到一个单独的AppDomain。你必须明确提供通过Remoting访问你的一些对象(或其他过程中的通信方式),但你可以卸载/的情况下,替换代码的文本文件的更改。

  • load the assembly into the currently executing AppDomain. This way, it has access to all the objects in your application. You, however, cannot unload the code again. You'll have to unload the whole AppDomain (i.e. your application)
  • load the assembly into a separate AppDomain. You'll have to explicitly provide access to some of your objects via Remoting (or other in process communication methods), but you can unload/replace the code in case the text file changes.

无论哪种方式,你将不得不使用反射来调用您的动态加载的代码。

Either way, you'll have to use reflection to call your dynamically loaded code.

这篇关于动态生成相同的装配间隙模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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