示例#1
0
        public async Task <(string result, MemoryStream bytes)> CompileScript(MemoryStream scriptAsStream) //fixed bug where async methods could not have refs
        {
            return(await Task.Run(() =>
            {
                var sourceText = SourceText.From(scriptAsStream); //postgres database initial encoding is utf8
                var syntaxTree = CSharpSyntaxTree.ParseText(sourceText, parseOptions);

                var compilation = CSharpCompilation.Create("moonmachinescript", new SyntaxTree[] { syntaxTree })
                                  .WithReferences(whitelist.GetWhitelistAsMetadata())
                                  .WithOptions(compilationOptions);

                var stringBuilder = new StringBuilder();
                var compiledbytes = new MemoryStream();
                EmitResult toILResult = compilation.Emit(compiledbytes);
                string compilationresult = handlescriptsresult(ref stringBuilder, toILResult);
                return (compilationresult, compiledbytes);
            }));
        }