c#中如何将字符串转换为代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/825107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to convert string to code in c#
提问by
I saw there is such question in c++ I am a very begginer and I need a very simple example how to do it . the user writes code in the text box and what I need o do is to execute it how???
我看到 c++ 中有这样的问题我是一个非常初学者,我需要一个非常简单的例子来做这件事。用户在文本框中编写代码,我需要做的是如何执行它???
回答by Reed Copsey
You can use the classes in the System.CodeDom namespace to compile C# into in-memory assemblies, and run them on the fly. Here is a mini-tutorial.
您可以使用 System.CodeDom 命名空间中的类将 C# 编译为内存程序集,并即时运行它们。 这是一个迷你教程。
Alternatively, you can use Reflection.Emitto construct code on the fly.
或者,您可以使用Reflection.Emit即时构建代码。