如何执行存储为字符串的代码 [英] how to execute a code which is stored as string

查看:69
本文介绍了如何执行存储为字符串的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何执行在C#中存储一个字符串的代码?

例如:
字符串str_test ="MessageBox.Show(" H World)";


我想运行存储在str_test中的代码?


在此先感谢大家..

how to execute a code which is stored a s a string in c#?

example:
string str_test="MessageBox.Show("H World")";


i want to run the code which is stored in str_test??


thanks in advance guys..

推荐答案

^ ]是与此有关的代码项目文章.
Here[^] is a Code Project article on this.


警告!

不幸的是,Cristian所引用的文章是完全错误的.它具有一个基本缺陷-由于无法卸载已加载的程序集而导致的内存泄漏.我在文章中添加了评论,警告所有人不要使用它.

另外,其中一位成员坚持认为,这篇文章窃了他的工作.请查看对文章的评论:一位评论者提供了更好的文章: http://www .west-wind.com//presentations/dynamicCode/DynamicCode.htm [使用CodeDom生成代码 [创建使用可重载插件的WPF应用程序... [ ^ ].

—SA
Warning!

Unfortunately, the article Cristian referenced is all wrong. It has a fundamental flaw — a memory leak due to the fact that it is impossible to unload a loaded assembly. I added my comment to the article warning everyone against using it.

Also, one of the members insists that this article plagiarizes his work. Please look at the comment to the article: one of the commenter offered much better article: http://www.west-wind.com//presentations/dynamicCode/DynamicCode.htm[^].

Also, I explain the problem of unloading and describe the solution using System.AppDomain which is probably the only correct approach. Please see:
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^].

—SA


这篇关于如何执行存储为字符串的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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