VS2005中怎么手写动态编译的代码?

来源:百度知道 编辑:UC知道 时间:2024/05/07 08:36:51
如题。

这东西是不是好难的,最好能给我个代码。
有一次老师给我们演示自己写的东西。
在TextBox或者是RichTextBox,在里面写了我们在VS2005中一样的代码。 比如,有一个方法。方法里面写上MessageBox.Show("aaaaa");
点个按钮,就能够执行这段代码了。
老师说是动态编译,还说什么一下子说不清。。
请高手帮忙解决下。。
自己找过一下MSDN上面好像说是Code....后面单词不记得了。。

我觉得要悬赏分不重要,答题的如果要分数,我可以追加。。

使用 CodeDom 吧?

呵呵,懒得写窗体,,就MSDN提供的DEMO,随便改了点代码,,你看看有用没有,呵呵,我用控制台程序,懒得做窗体了,你可以把 code 变量,用一个TextBox或者RichTextBox来输入。

MSDN里有,其实.net的对象,以及用法,MSDN都写得很详细了,有需要就查查MSDN,问题就解决了。

using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;

using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication3
{
class Program
{
static void Main( string[] args )
{
//create the code dom provider
CodeDomProvider provider = CodeDomProvider.CreateProvider( "CSharp" );

// Configure a CompilerParameters that links System.dll
// and produces the specified executable file.
String[] referenceAssemblies = { "System.dll" };
CompilerParameters cp = new CompilerPar