Skip to content

Commit

Permalink
Change property back to field
Browse files Browse the repository at this point in the history
  • Loading branch information
slozier committed Apr 5, 2022
1 parent 910e6a0 commit 2845063
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
12 changes: 6 additions & 6 deletions Src/Microsoft.Scripting/Runtime/SharedIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ private void InitializeInput() {
_inputEncoding = Console.InputEncoding;
_inputReader = Console.In;
#elif FEATURE_BASIC_CONSOLE
_inputEncoding = Encoding.Default;
_inputStream = new TextStream(Console.In, _inputEncoding);
_inputReader = Console.In;
_inputEncoding = Encoding.Default;
_inputStream = new TextStream(Console.In, _inputEncoding);
_inputReader = Console.In;
#else
_inputEncoding = Encoding.UTF8;
_inputStream = Stream.Null;
_inputReader = TextReader.Null;
_inputEncoding = Encoding.UTF8;
_inputStream = Stream.Null;
_inputReader = TextReader.Null;
#endif
} catch (PlatformNotSupportedException) {
// When on BlazorWebassembly, this exception is thrown.
Expand Down
19 changes: 7 additions & 12 deletions Src/Microsoft.Scripting/Utils/ConsoleInputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ namespace Microsoft.Scripting.Utils {
/// This class wraps the standard input stream with a buffer that ensures that enough data are read from the underlying stream.
/// </summary>
public sealed class ConsoleInputStream : Stream {
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
private static ConsoleInputStream _instance = null;

public static ConsoleInputStream Instance {
// When there is no input stream available (e.g. BlazorWasm), propagate PlatformNotSupportedException
get {
if (_instance == null) _instance = new();
return _instance;
}
}
public static readonly ConsoleInputStream Instance = new ConsoleInputStream();

// we use 0x1000 to be safe (MSVCRT uses this value for stdin stream buffer).
private const int MinimalBufferSize = 0x1000;
Expand All @@ -35,9 +26,13 @@ public static ConsoleInputStream Instance {
private readonly byte[] _buffer = new byte[MinimalBufferSize];
private int _bufferPos;
private int _bufferSize;

private ConsoleInputStream() {
_input = Console.OpenStandardInput();
try {
_input = Console.OpenStandardInput();
} catch (PlatformNotSupportedException) {
_input = Stream.Null;
}
}

public override bool CanRead {
Expand Down

0 comments on commit 2845063

Please sign in to comment.