未验证 提交 f9ce10f9 编写于 作者: M Maxim Lipnin 提交者: GitHub

Mark System.Console APIs as unsupported on Android (#50931)

Annotated public System.Console APIs throwing PNSE on Android.  

Part of #47911.
上级 c7e02f37
......@@ -7,6 +7,7 @@
namespace Microsoft.Extensions.Logging.Console
{
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
internal sealed class AnsiParsingLogConsole : IConsole
{
......
......@@ -47,7 +47,8 @@ public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnu
_optionsReloadToken = _options.OnChange(ReloadLoggerOptions);
_messageQueue = new ConsoleLoggerProcessor();
if (DoesConsoleSupportAnsi())
// TODO update when https://github.com/dotnet/runtime/issues/44922 implemented
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || DoesWindowsConsoleSupportAnsi())
{
_messageQueue.Console = new AnsiLogConsole();
_messageQueue.ErrorConsole = new AnsiLogConsole(stdErr: true);
......@@ -59,12 +60,8 @@ public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnu
}
}
private static bool DoesConsoleSupportAnsi()
private static bool DoesWindowsConsoleSupportAnsi()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return true;
}
// for Windows, check the console mode
var stdOutHandle = Interop.Kernel32.GetStdHandle(Interop.Kernel32.STD_OUTPUT_HANDLE);
if (!Interop.Kernel32.GetConsoleMode(stdOutHandle, out int consoleMode))
......
......@@ -8,51 +8,64 @@ namespace System
{
public static partial class Console
{
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static System.ConsoleColor BackgroundColor { get { throw null; } set { } }
public static int BufferHeight { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public static int BufferWidth { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public static int BufferHeight { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android"), System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public static int BufferWidth { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android"), System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static bool CapsLock { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static int CursorLeft { get { throw null; } set { } }
public static int CursorSize { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public static int CursorSize { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android"), System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static int CursorTop { get { throw null; } set { } }
public static bool CursorVisible { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] set { } }
public static bool CursorVisible { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android"), System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] set { } }
public static System.IO.TextWriter Error { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static System.ConsoleColor ForegroundColor { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static System.IO.TextReader In { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static System.Text.Encoding InputEncoding { get { throw null; } set { } }
public static bool IsErrorRedirected { get { throw null; } }
public static bool IsInputRedirected { get { throw null; } }
public static bool IsOutputRedirected { get { throw null; } }
public static bool KeyAvailable { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static int LargestWindowHeight { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static int LargestWindowWidth { get { throw null; } }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static bool NumberLock { get { throw null; } }
public static System.IO.TextWriter Out { get { throw null; } }
public static System.Text.Encoding OutputEncoding { get { throw null; } set { } }
public static string Title { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] set { } }
public static System.Text.Encoding OutputEncoding { get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] set { } }
public static string Title { [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android"), System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static bool TreatControlCAsInput { get { throw null; } set { } }
public static int WindowHeight { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public static int WindowHeight { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android"), System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public static int WindowLeft { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public static int WindowTop { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public static int WindowWidth { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public static int WindowWidth { [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android"), System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static event System.ConsoleCancelEventHandler? CancelKeyPress { add { } remove { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static void Beep() { }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static void Beep(int frequency, int duration) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
public static void Clear() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static (int Left, int Top) GetCursorPosition() { throw null; }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
......@@ -61,27 +74,36 @@ public static partial class Console
public static void MoveBufferArea(int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop, char sourceChar, System.ConsoleColor sourceForeColor, System.ConsoleColor sourceBackColor) { }
public static System.IO.Stream OpenStandardError() { throw null; }
public static System.IO.Stream OpenStandardError(int bufferSize) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static System.IO.Stream OpenStandardInput() { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static System.IO.Stream OpenStandardInput(int bufferSize) { throw null; }
public static System.IO.Stream OpenStandardOutput() { throw null; }
public static System.IO.Stream OpenStandardOutput(int bufferSize) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static int Read() { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static System.ConsoleKeyInfo ReadKey() { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static System.ConsoleKeyInfo ReadKey(bool intercept) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static string? ReadLine() { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static void ResetColor() { }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static void SetBufferSize(int width, int height) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static void SetCursorPosition(int left, int top) { }
public static void SetError(System.IO.TextWriter newError) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static void SetIn(System.IO.TextReader newIn) { }
public static void SetOut(System.IO.TextWriter newOut) { }
......
......@@ -33,6 +33,7 @@ public static class Console
private static ConsoleCancelEventHandler? s_cancelCallbacks;
private static ConsolePal.ControlCHandlerRegistrar? s_registrar;
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static TextReader In
{
......@@ -57,6 +58,7 @@ static TextReader EnsureInitialized()
}
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static Encoding InputEncoding
{
......@@ -113,6 +115,7 @@ public static Encoding OutputEncoding
}
return encoding;
}
[UnsupportedOSPlatform("android")]
set
{
CheckNonNull(value, nameof(value));
......@@ -154,12 +157,14 @@ public static bool KeyAvailable
}
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static ConsoleKeyInfo ReadKey()
{
return ConsolePal.ReadKey(false);
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static ConsoleKeyInfo ReadKey(bool intercept)
{
......@@ -280,6 +285,7 @@ static StrongBox<bool> EnsureInitialized()
public static int CursorSize
{
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
get { return ConsolePal.CursorSize; }
[SupportedOSPlatform("windows")]
......@@ -300,6 +306,7 @@ public static bool CapsLock
internal const ConsoleColor UnknownColor = (ConsoleColor)(-1);
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static ConsoleColor BackgroundColor
{
......@@ -307,6 +314,7 @@ public static ConsoleColor BackgroundColor
set { ConsolePal.BackgroundColor = value; }
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static ConsoleColor ForegroundColor
{
......@@ -314,6 +322,7 @@ public static ConsoleColor ForegroundColor
set { ConsolePal.ForegroundColor = value; }
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static void ResetColor()
{
......@@ -322,6 +331,7 @@ public static void ResetColor()
public static int BufferWidth
{
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
get { return ConsolePal.BufferWidth; }
[SupportedOSPlatform("windows")]
......@@ -330,6 +340,7 @@ public static int BufferWidth
public static int BufferHeight
{
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
get { return ConsolePal.BufferHeight; }
[SupportedOSPlatform("windows")]
......@@ -358,6 +369,7 @@ public static int WindowTop
public static int WindowWidth
{
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
get { return ConsolePal.WindowWidth; }
[SupportedOSPlatform("windows")]
......@@ -366,6 +378,7 @@ public static int WindowWidth
public static int WindowHeight
{
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
get { return ConsolePal.WindowHeight; }
[SupportedOSPlatform("windows")]
......@@ -384,12 +397,14 @@ public static void SetWindowSize(int width, int height)
ConsolePal.SetWindowSize(width, height);
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static int LargestWindowWidth
{
get { return ConsolePal.LargestWindowWidth; }
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static int LargestWindowHeight
{
......@@ -400,10 +415,12 @@ public static bool CursorVisible
{
[SupportedOSPlatform("windows")]
get { return ConsolePal.CursorVisible; }
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
set { ConsolePal.CursorVisible = value; }
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static int CursorLeft
{
......@@ -411,6 +428,7 @@ public static int CursorLeft
set { SetCursorPosition(value, CursorTop); }
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static int CursorTop
{
......@@ -423,6 +441,7 @@ public static int CursorTop
/// <remarks>
/// Columns are numbered from left to right starting at 0. Rows are numbered from top to bottom starting at 0.
/// </remarks>
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static (int Left, int Top) GetCursorPosition()
{
......@@ -433,6 +452,7 @@ public static string Title
{
[SupportedOSPlatform("windows")]
get { return ConsolePal.Title; }
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
set
{
......@@ -440,6 +460,7 @@ public static string Title
}
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static void Beep()
{
......@@ -464,11 +485,13 @@ public static void MoveBufferArea(int sourceLeft, int sourceTop, int sourceWidth
ConsolePal.MoveBufferArea(sourceLeft, sourceTop, sourceWidth, sourceHeight, targetLeft, targetTop, sourceChar, sourceForeColor, sourceBackColor);
}
[UnsupportedOSPlatform("android")]
public static void Clear()
{
ConsolePal.Clear();
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static void SetCursorPosition(int left, int top)
{
......@@ -481,6 +504,7 @@ public static void SetCursorPosition(int left, int top)
ConsolePal.SetCursorPosition(left, top);
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static event ConsoleCancelEventHandler? CancelKeyPress
{
......@@ -515,6 +539,7 @@ public static void SetCursorPosition(int left, int top)
}
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static bool TreatControlCAsInput
{
......@@ -522,12 +547,14 @@ public static bool TreatControlCAsInput
set { ConsolePal.TreatControlCAsInput = value; }
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static Stream OpenStandardInput()
{
return ConsolePal.OpenStandardInput();
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static Stream OpenStandardInput(int bufferSize)
{
......@@ -569,6 +596,7 @@ public static Stream OpenStandardError(int bufferSize)
return ConsolePal.OpenStandardError();
}
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static void SetIn(TextReader newIn)
{
......@@ -616,6 +644,7 @@ private static void CheckNonNull(object obj, string paramName)
// the inlined console writelines from them.
//
[MethodImplAttribute(MethodImplOptions.NoInlining)]
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static int Read()
{
......@@ -623,6 +652,7 @@ public static int Read()
}
[MethodImplAttribute(MethodImplOptions.NoInlining)]
[UnsupportedOSPlatform("android")]
[UnsupportedOSPlatform("browser")]
public static string? ReadLine()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册