dynamic-assemblies

Using Roslyn Emit method with a ModuleBuilder instead of a MemoryStream

隐身守侯 提交于 2019-11-27 23:27:27
问题 I was having trouble with performance when using Roslyn to compile to a dynamic assembly. Compilation was taking ~3 seconds, compared to ~300 milliseconds to compile the same code when using the CodeDom compiler. Here's a pared-down version of the code I'm using to do the compilation: var compilation = CSharpCompilation.Create( "UserPayRules.dll", syntaxTrees, assembliesToAdd); using (var stream = new MemoryStream()) { stopWatch.Start(); var result = compilation.Emit(stream); stopWatch.Stop()