I'm trying to integrate c# scripting into my database application. I'm using the globals object to make global variables accessible from the script.
I'm not happy with the wait time if the script is compiled for the first time.
How can I save and load the compilation to avoid the wait time?
Script<object> script = CSharpScript.Create(scriptCode, globalsType: typeof(MyGlobals));
script.Compile(); //<-- load the Compilation from database/file here
script.RunAsync(myGlobalsInstance).Wait();
You can create a CSharpScript, then get the compilation via GetCompilation
to get the compilation.
var script = CSharpScript.Create("script..");
var compilation = script.GetCompilation();
From the compilation, you can actually compilation.Emit()
the dll and pdb to disk or memory. The tricky (and roslyn internal bit) is how to get the delegate of the code to execute, once you have the assembly. You can see how roslyn does it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With