當前位置:開發者網絡 >> 技術教程 >> .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");
}

相關文章: