public static void EvalInteraction(string code) { var cancellationToken = new CancellationToken(); Script <object> newScript; if (state == null) { newScript = CSharpScript.Create <object>(code, scriptOptions, globals.GetType(), assemblyLoader: null); } else { newScript = state.Script.ContinueWith(code, scriptOptions); } var diagnostics = newScript.Compile(cancellationToken); if (diagnostics.Length > 0) { foreach (var error in diagnostics) { sbErr.Append(error.ToString()); } return; } var task = (state == null) ? newScript.RunAsync(globals, catchException: e => false, cancellationToken: cancellationToken) : newScript.RunFromAsync(state, catchException: e => false, cancellationToken: cancellationToken); state = task.GetAwaiter().GetResult(); //state = state == null ? CSharpScript.RunAsync(code, scriptOptions).Result : // state.ContinueWithAsync(code, scriptOptions).Result; if (state.ReturnValue != null && !string.IsNullOrEmpty(state.ReturnValue.ToString())) { sbOut.Append(state.ReturnValue.ToString()); } }
private Script <object> TryCompile(Script previousScript, string code, string path, ScriptOptions options) { Script script; var scriptOptions = options.WithFilePath(path); if (previousScript != null) { script = previousScript.ContinueWith(code, scriptOptions); } else { script = _replServiceProvider.CreateScript <object>(code, scriptOptions, _globals.GetType(), _assemblyLoader); } var diagnostics = script.Compile(); if (diagnostics.HasAnyErrors()) { DisplayInteractiveErrors(diagnostics, Console.Error); return(null); } return((Script <object>)script); }
private Script <object> TryCompile(Script previousScript, string code, string path, ScriptOptions options) { Script script; var scriptOptions = options.WithFilePath(path); if (previousScript != null) { script = previousScript.ContinueWith(code, scriptOptions); } else { script = _replServiceProvider.CreateScript <object>(code, scriptOptions, _globals.GetType(), _assemblyLoader); } var diagnostics = script.Build(); if (diagnostics.HasAnyErrors()) { DisplayInteractiveErrors(diagnostics, Console.Error); return(null); } // TODO: Do we want to do this? // Pros: immediate feedback for assemblies that can't be loaded. // Cons: maybe we won't need them //foreach (PortableExecutableReference reference in script.GetCompilation().DirectiveReferences) //{ // LoadReference(reference, suppressWarnings: false); //} return((Script <object>)script); }