Exemple #1
0
        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()
                           ));
            }
        }) {}
Exemple #2
0
 public CompiledCode(string code, CodeTemplateForFooClass template) : this(code, template, "InjectedCodeAssembly")
 {
 }