CSharpCodeProvider 學習 c#

  using (CSharpCodeProvider provider = new CSharpCodeProvider())
            {
                CompilerParameters options = new CompilerParameters();
                options.GenerateInMemory = true;

                CompilerResults result = provider.CompileAssemblyFromSource(options, sb.ToString());

                if (result.Errors.HasErrors)
                {
                    StringBuilder str = new StringBuilder();
                    foreach (CompilerError eoor in result.Errors)
                    {
                        str.AppendFormat("{0} {1}", eoor.Line, eoor.ErrorText);
                    }
                    Console.WriteLine(str.ToString());
                }
                else
                {
                    Console.WriteLine("Compile finished");
                    Type codeType = result.CompiledAssembly.GetType("Driver");
                    codeType.InvokeMember("Run", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, null);
                    
                }
            }

發佈了36 篇原創文章 · 獲贊 13 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章