public CompiledCode(string code, CodeTemplateForFooClass template, string assemblyName) : base(() => { using (var dll = new MemoryStream()) { var emitResult = CSharpCompilation.Create( assemblyName, new[] { CSharpSyntaxTree.ParseText(code) }, template.Dependencies().References(), options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) ).Emit(dll); if (!emitResult.Success) { return(new CompiledCode( new CompileError( String .Join( Environment.NewLine, emitResult .Diagnostics .Select(d => d.GetMessage()) ) ) )); } return(new CompiledCode( dll .ToArray() .ToList() )); } }) {}
public CompiledCode(string code, CodeTemplateForFooClass template) : this(code, template, "InjectedCodeAssembly") { }