• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • C#編譯器

    發表于:2007-05-25來源:作者:點擊數: 標簽:以下外人寫的編譯器一個
    以下是國外人寫的一個C#編譯器,當然由于他依然使用的.Net下的FCL,所以不可能是真正意義上的編譯器, 飛刀我介紹出來,只是可以讓大家擺脫csc的約束,在Win界面上完成編譯. 你必須以下面的步驟完成: 1.建立一個CSharpCodeProvider 實例(如果是使用Visual B
    以下是國外人寫的一個C#編譯器,當然由于他依然使用的.Net下的FCL,所以不可能是真正意義上的編譯器, 飛刀我介紹出來,只是可以讓大家擺脫csc的約束,在Win界面上完成編譯.


    你必須以下面的步驟完成:

    1.建立一個CSharpCodeProvider 實例(如果是使用Visual Basic則使用VBCodeProvider)
    2.包含接口ICodeCompiler
    3.提供CompilerParameters的參數
    4.使用CompileAssemblyFromSource方法編譯。
    5.運行CompilerResults
    6.執行編譯好的程序


    編譯的代碼可以是寫在文本框中的字符串,當然也可以源文件。

    以下是源代碼:),過兩天我修改一下后提供整個源代碼:)

    private void button1_Click(object sender, System.EventArgs e)
    {
    CSharpCodeProvider codeProvider = new CSharpCodeProvider();
    // For Visual Basic Compiler try this :
    //Microsoft.VisualBasic.VBCodeProvider

    ICodeCompiler compiler = codeProvider.CreateCompiler();
    CompilerParameters parameters = new CompilerParameters();

    parameters.GenerateExecutable = true;
    if (appName.Text == "")
    {
    System.Windows.Forms.MessageBox.Show(this,
    "Application name cannot be empty");
    return ;
    }

    parameters.OutputAssembly = appName.Text.ToString();

    if (mainClass.Text.ToString() == "")
    {
    System.Windows.Forms.MessageBox.Show(this,
    "Main Class Name cannot be empty");
    return ;
    }

    parameters.MainClass = mainClass.Text.ToString();
    parameters.IncludeDebugInformation = includeDebug.Checked;

    // Add available assemblies - this should be enough for the simplest
    // applications.
    foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
    {
    parameters.ReferencedAssemblies.Add(asm.Location);
    }

    String code = textBox1.Text.ToString();
    //System.Windows.Forms.MessageBox.Show(this, code);

    CompilerResults results = compiler.CompileAssemblyFromSource(parameters,
    code);

    if (results.Errors.Count > 0)
    {
    string errors = "Compilation failed:\n";
    foreach (CompilerError err in results.Errors)
    {
    errors += err.ToString() + "\n";
    }
    System.Windows.Forms.MessageBox.Show(this, errors,
    "There were compilation errors");
    }
    else
    {
    #region Executing generated executable
    // try to execute application
    try
    {
    if (!System.IO.File.Exists(appName.Text.ToString()))
    {
    MessageBox.Show(String.Format("Can't find {0}", appName),
    "Can't execute.", MessageBoxButtons.OK,
    MessageBoxIcon.Error);
    return;
    }
    ProcessStartInfo pInfo = new ProcessStartInfo(appName.Text.ToString());
    Process.Start(pInfo);
    }
    catch (Exception ex)
    {
    MessageBox.Show(String.Format("Error while executing {0}",
    appName) + ex.ToString(), "Can't execute.",
    MessageBoxButtons.OK, MessageBoxIcon.Error);
    }

    #endregion

    }

    }

    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>