CompilerParameters GetCompilerParameters(IList<TextExpressionCompilerError> messages) { CompilerParameters compilerParameters = new CompilerParameters(); compilerParameters.GenerateExecutable = false; compilerParameters.GenerateInMemory = false; if (this.IsVB && !string.IsNullOrWhiteSpace(this.settings.RootNamespace)) { compilerParameters.CompilerOptions = string.Concat("/rootnamespace:", this.settings.RootNamespace); } List<AssemblyReference> assemblies = this.settings.ForImplementation ? new List<AssemblyReference>(TextExpression.GetReferencesForImplementation(this.settings.Activity)) : new List<AssemblyReference>(TextExpression.GetReferences(this.settings.Activity)); assemblies.AddRange(TextExpression.DefaultReferences); foreach (AssemblyReference assemblyReference in assemblies) { if (assemblyReference == null) { continue; } assemblyReference.LoadAssembly(); if (assemblyReference.Assembly == null) { TextExpressionCompilerError warning = new TextExpressionCompilerError(); warning.IsWarning = true; warning.Message = SR.TextExpressionCompilerUnableToLoadAssembly(assemblyReference.AssemblyName); messages.Add(warning); continue; } if (assemblyReference.Assembly.CodeBase == null) { TextExpressionCompilerError warning = new TextExpressionCompilerError(); warning.IsWarning = true; warning.Message = SR.TextExpressionCompilerNoCodebase(assemblyReference.AssemblyName); messages.Add(warning); continue; } string fileName = new Uri(assemblyReference.Assembly.CodeBase).LocalPath; compilerParameters.ReferencedAssemblies.Add(fileName); } return compilerParameters; }
TextExpressionCompilerResults CompileInMemory() { List<TextExpressionCompilerError> messages = new List<TextExpressionCompilerError>(); CompilerParameters compilerParameters = GetCompilerParameters(messages); CompilerResults compilerResults = null; using (CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider(this.settings.Language)) { compilerResults = codeDomProvider.CompileAssemblyFromDom(compilerParameters, this.compileUnit); } TextExpressionCompilerResults results = new TextExpressionCompilerResults(); if (compilerResults.Errors == null || !compilerResults.Errors.HasErrors) { results.ResultType = compilerResults.CompiledAssembly.GetType(this.activityFullName); } results.HasSourceInfo = this.symbols != null; bool hasErrors = false; if (compilerResults.Errors != null && (compilerResults.Errors.HasWarnings || compilerResults.Errors.HasErrors)) { foreach (CompilerError ce in compilerResults.Errors) { TextExpressionCompilerError message = new TextExpressionCompilerError(); message.Message = ce.ErrorText; message.Number = ce.ErrorNumber; if (results.HasSourceInfo) { message.SourceLineNumber = ce.Line; } else { message.SourceLineNumber = -1; } message.IsWarning = ce.IsWarning; messages.Add(message); hasErrors |= !message.IsWarning; } } if (messages != null && messages.Count > 0) { results.SetMessages(messages, hasErrors); } return results; }