/// <summary> /// Executes the given code in a remote location /// </summary> public static void Execute(string code, IEnumerable <string> namespaces = null) { code = _prepare_code(code, _prepare_namespaces(namespaces)); if (code == "") { return; } IExecute exe = null; try { exe = CSScript.LoadCode(code) .CreateObject("*") .AlignToInterface <IExecute>(); } catch (CompilerException e) when(e.Message.Contains("error CS0103")) { var ex = new MissingNamespaceException(e.Message.Split(new[] { ": error" }, StringSplitOptions.RemoveEmptyEntries)[1], e); Console.WriteLine(ex); throw ex; } catch (Exception e) { Console.WriteLine(e); throw e; } try { exe.Execute(); } catch (Exception e) { Console.WriteLine(e); } }
public static object ExecuteReturn(string code, IEnumerable <string> namespaces = null) { code = _prepare_code(code, _prepare_namespaces(namespaces)); if (code == "") { return(null); } IExecute <object> exe = null; try { exe = CSScript.LoadCode(code) .CreateObject("*") .AlignToInterface <IExecute <object> >(); } catch (CompilerException e) when(e.Message.Contains("error CS0103")) { var ex = new MissingNamespaceException(e.Message, e); Console.WriteLine(ex); throw ex; } catch (Exception e) { Console.WriteLine(e); throw e; } try { return(exe.Execute()); } catch (Exception e) { Console.WriteLine(e); } return(null); }