/// 创建相应脚本语言的编译器 /// </summary> private void createCompiler(string strLanguage, bool debugMode, string strAssemblyFileName) { this.theParameters = new CompilerParameters(); this.theParameters.OutputAssembly = System.IO.Path.Combine(System.IO.Path.GetTempPath(), strAssemblyFileName + ".dll"); this.theParameters.GenerateExecutable = false; this.theParameters.GenerateInMemory = true; if(debugMode) { this.theParameters.IncludeDebugInformation = true; this.theParameters.CompilerOptions += "/define:TRACE=1 /define:DEBUG=1 "; } else { this.theParameters.IncludeDebugInformation = false; this.theParameters.CompilerOptions += "/define:TRACE=1 "; } AddReference("System.dll"); AddReference("System.Data.dll"); AddReference("System.Xml.dll"); strLanguage = strLanguage.ToLower(); if("visualbasic" == strLanguage || "vb" == strLanguage) { theProvider = new Microsoft.VisualBasic.VBCodeProvider(); if(debugMode) theParameters.CompilerOptions += "/debug:full /optimize- /optionexplicit+ /optionstrict+ /optioncompare:text /imports:Microsoft.VisualBasic,System,System.Collections,System.Diagnostics "; else theParameters.CompilerOptions += "/optimize /optionexplicit+ /optionstrict+ /optioncompare:text /imports:Microsoft.VisualBasic,System, System.Collections,System.Diagnostics "; AddReference("Microsoft.VisualBasic.dll"); } else if("jscript" == strLanguage || "js" == strLanguage) { theProvider = new Microsoft.JScript.JScriptCodeProvider(); AddReference("Microsoft.JScript.dll"); } else if("csharp" == strLanguage || "cs" == strLanguage || "c#" == strLanguage) { theProvider = new Microsoft.CSharp.CSharpCodeProvider(); if(!debugMode) theParameters.CompilerOptions += "/optimize "; } // else if("jsharp" == strLanguage || "vj" == strLanguage || "j#" == strLanguage) // { // theProvider = new Microsoft.VJSharp.VJSharpCodeProvider(); // if(!debugMode) // theParameters.CompilerOptions += "/optimize "; // } else throw new System.Exception("指定的脚本语言不被支持。"); } /**//// <summary> /// 添加引用对象。 /// </summary> /// <param name="__strAssemblyName">引用的文件名</param> public void AddReference(string __strAssemblyName) { theParameters.ReferencedAssemblies.Add(__strAssemblyName); } |