当前位置:开发者网络 >> 技术教程 >> .NET教程 >> 面向对象编程 >> 内容
精彩推荐
分类最新教程
分类热点教程
  
如何 动态编译自己写的代码
作者:未知
日期:2004-09-28
人气:
投稿:snow(转贴)
来源:未知
字体:
收藏:加入浏览器收藏
以下正文:
CSharpCodeProvider _coder=new CSharpCodeProvider();
ICodeCompiler complier=_coder.CreateCompiler();
CompilerParameters _par=new CompilerParameters();
_par.GenerateExecutable=true;

_par.OutputAssembly="sy1.exe";//设置应用程序名
_par.MainClass="sy1";//设置主类

_par.IncludeDebugInformation=true;

foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
_par.ReferencedAssemblies.Add(asm.Location);
}

string get_Code=_code;

CompilerResults _res=complier.CompileAssemblyFromSource(_par,get_Code);

if(_res.Errors.Count>0)
{
ErrInfo pEi=new ErrInfo();
pEi.Show();
ListBox getList=pEi.getList;
foreach(CompilerError err in _res.Errors)
{

getList.Items.Add(err.ErrorText);
}
}
else
{
MessageBox.Show("success");
}

相关文章: