Ejemplo n.º 1
0
        public static object CompileAndExecuteCode(Window window, string formulaCode, out bool isError)
        {
            isError = false;
            try
            {
                Microsoft.CodeAnalysis.Scripting.Script <object> script = CSharpScript.Create(formulaCode, ScriptOptions.Default.
                                                                                              WithImports("System", "System.Collections", "OfficeOpenXml", "System.IO").
                                                                                              WithReferences(typeof(ExcelPackage).Assembly));

                Microsoft.CodeAnalysis.Scripting.ScriptState <object> result = script.RunAsync().Result;
                return(result.ReturnValue);
            }
            catch (CompilationErrorException ex)
            {
                string errors = ex.Diagnostics.Select(d => d.GetMessage()).First().ToString();
                isError = true;
                MessageBox.Show(window, errors, string.Empty, MessageBoxButton.OK);
                return(null);
            }
        }
Ejemplo n.º 2
0
 public Script(string path, T api)
 {
     this.api = api;
     script   = CSharpScript.Create(File.ReadAllText(path), globalsType: typeof(T));
 }