Fix disposed TextWriter bug, add System.Collections to default using

This commit is contained in:
Sinai 2022-01-08 17:56:48 +11:00
parent 44e57c32c3
commit 62354b6aa2

View File

@ -27,6 +27,7 @@ namespace UnityExplorer.CSConsole
private static HashSet<string> usingDirectives; private static HashSet<string> usingDirectives;
private static StringBuilder evaluatorOutput; private static StringBuilder evaluatorOutput;
private static StringWriter evaluatorStringWriter;
public static CSConsolePanel Panel => UIManager.GetPanel<CSConsolePanel>(UIManager.Panels.CSConsole); public static CSConsolePanel Panel => UIManager.GetPanel<CSConsolePanel>(UIManager.Panels.CSConsole);
public static InputFieldRef Input => Panel.Input; public static InputFieldRef Input => Panel.Input;
@ -46,6 +47,7 @@ namespace UnityExplorer.CSConsole
"System", "System",
"System.Linq", "System.Linq",
"System.Text", "System.Text",
"System.Collections",
"System.Collections.Generic", "System.Collections.Generic",
"UnityEngine", "UnityEngine",
#if CPP #if CPP
@ -130,6 +132,12 @@ namespace UnityExplorer.CSConsole
#region Evaluating #region Evaluating
private static void GenerateTextWriter()
{
evaluatorOutput = new StringBuilder();
evaluatorStringWriter = new StringWriter(evaluatorOutput);
}
public static void ResetConsole() => ResetConsole(true); public static void ResetConsole() => ResetConsole(true);
public static void ResetConsole(bool logSuccess = true) public static void ResetConsole(bool logSuccess = true)
@ -140,8 +148,8 @@ namespace UnityExplorer.CSConsole
if (Evaluator != null) if (Evaluator != null)
Evaluator.Dispose(); Evaluator.Dispose();
evaluatorOutput = new StringBuilder(); GenerateTextWriter();
Evaluator = new ScriptEvaluator(new StringWriter(evaluatorOutput)) Evaluator = new ScriptEvaluator(evaluatorStringWriter)
{ {
InteractiveBaseClass = typeof(ScriptInteraction) InteractiveBaseClass = typeof(ScriptInteraction)
}; };
@ -176,6 +184,12 @@ namespace UnityExplorer.CSConsole
if (SRENotSupported) if (SRENotSupported)
return; return;
if (evaluatorStringWriter == null || evaluatorOutput == null)
{
GenerateTextWriter();
Evaluator._textWriter = evaluatorStringWriter;
}
try try
{ {
// Compile the code. If it returned a CompiledMethod, it is REPL. // Compile the code. If it returned a CompiledMethod, it is REPL.