/// <summary>Compile the code and return an Assembly type</summary> /// <returns></returns> public NetComBridge.Assembly Compile() { if (!Compiler.isAlreadyCompiled) { System.CodeDom.Compiler.CompilerResults crResults = this.provider.CompileAssemblyFromSource(this.cpParams, this.sbCode.ToString()); if (crResults.Errors.HasErrors) { StringBuilder sbErrors = new StringBuilder(); foreach (System.CodeDom.Compiler.CompilerError err in crResults.Errors) { sbErrors.AppendLine(System.Text.RegularExpressions.Regex.Replace(err.ToString(), @"\w:\\[^(]+", "line")); } throw new System.ApplicationException(sbErrors.ToString()); } else { System.Reflection.Assembly compiledAssembly = crResults.CompiledAssembly; NetComBridge.Bridge bridge = new Bridge(); Compiler.assembly = new Assembly(bridge, compiledAssembly); Compiler.isAlreadyCompiled = true; Compiler.sbPreviousCode = this.sbCode; return(assembly); } } else if (!Compiler.sbPreviousCode.Equals(this.sbCode)) { throw new ApplicationException("The code is already compiled.\r\nReopen Excel to compile again.\r\n"); } else { NetComBridge.Bridge bridge = new Bridge(); return(Compiler.assembly); } }
/// <summary>Compile the code and return an Assembly type</summary> /// <returns></returns> public NetComBridge.Assembly Compile() { if ( !Compiler.isAlreadyCompiled) { System.CodeDom.Compiler.CompilerResults crResults = this.provider.CompileAssemblyFromSource(this.cpParams, this.sbCode.ToString()); if (crResults.Errors.HasErrors){ StringBuilder sbErrors = new StringBuilder(); foreach (System.CodeDom.Compiler.CompilerError err in crResults.Errors) { sbErrors.AppendLine(System.Text.RegularExpressions.Regex.Replace( err.ToString(), @"\w:\\[^(]+", "line") ); } throw new System.ApplicationException(sbErrors.ToString() ); }else{ System.Reflection.Assembly compiledAssembly = crResults.CompiledAssembly; NetComBridge.Bridge bridge = new Bridge(); Compiler.assembly = new Assembly(bridge, compiledAssembly); Compiler.isAlreadyCompiled = true; Compiler.sbPreviousCode = this.sbCode; return assembly; } }else if (!Compiler.sbPreviousCode.Equals(this.sbCode)) { throw new ApplicationException("The code is already compiled.\r\nReopen Excel to compile again.\r\n"); }else{ NetComBridge.Bridge bridge = new Bridge(); return Compiler.assembly; } }