Repository: dotnet/runtime
File: src/libraries/System.Console/src/System/ConsolePal.Windows.cs (C#)

Code before:
        // you can still spawn a Windows app via CreateProcess and read stdout
        // and stderr. So, we always need to check each handle independently for validity
        // by trying to write or read to it, unless it is -1.
        private static unsafe bool ConsoleHandleIsWritable(IntPtr outErrHandle)
        {
            // Windows apps may have non-null valid looking handle values for
            // stdin, stdout and stderr, but they may not be readable or
            // writable.  Verify this by calling WriteFile in the
            // appropriate modes. This must handle console-less Windows apps.
            byte junkByte = 0x41;
            int r = Interop.Kernel32.WriteFile(outErrHandle, &junkByte, 0, out _, IntPtr.Zero);
            return r != 0; // In Win32 apps w/ no console, bResult should be 0 for failure.
        }

        // Checks whether stdin is readable.  Do NOT pass
        // stdout or stderr here!
        private static unsafe bool ConsoleHandleIsReadable(IntPtr inHandle)
        {
            // Windows apps may have non-null valid looking handle values for
            // stdin, stdout and stderr, but they may not be readable or
            // writable.  Verify this by calling ReadFile in the
            // appropriate modes. This must handle console-less Windows apps.
            int r = Interop.Kernel32.ReadFile(inHandle, null, 0, out _, IntPtr.Zero);
            return r != 0; // In Win32 apps w/ no console, bResult should be 0 for failure.
        }

        public static SafeFileHandle OpenStandardInputHandle() => OpenStandardHandle(Interop.Kernel32.HandleTypes.STD_INPUT_HANDLE);

        public static SafeFileHandle OpenStandardOutputHandle() => OpenStandardHandle(Interop.Kernel32.HandleTypes.STD_OUTPUT_HANDLE);

        public static SafeFileHandle OpenStandardErrorHandle() => OpenStandardHandle(Interop.Kernel32.HandleTypes.STD_ERROR_HANDLE);

        private static SafeFileHandle OpenStandardHandle(int handleType)
        {
            IntPtr handle = Interop.Kernel32.GetStdHandle(handleType);
            return new SafeFileHandle(handle, ownsHandle: false);
        }

        public static Encoding InputEncoding
        {
            get { return EncodingHelper.GetSupportedConsoleEncoding((int)Interop.Kernel32.GetConsoleCP()); }
        }

        public static void SetConsoleInputEncoding(Encoding enc)
        {
            if (enc.CodePage != UnicodeCodePage)
            {
                if (!Interop.Kernel32.SetConsoleCP(enc.CodePage))
                {
                    HandleSetConsoleEncodingError(Marshal.GetLastPInvokeError());
                }

Review comment (suggestion):
We don't need this method anymore.

```suggestion
```

Code after:
        // you can still spawn a Windows app via CreateProcess and read stdout
        // and stderr. So, we always need to check each handle independently for validity
        // by trying to write or read to it, unless it is -1.
        private static unsafe bool ConsoleHandleIsWritable(IntPtr outErrHandle)
        {
            // Windows apps may have non-null valid looking handle values for
            // stdin, stdout and stderr, but they may not be readable or
            // writable.  Verify this by calling WriteFile in the
            // appropriate modes. This must handle console-less Windows apps.
            byte junkByte = 0x41;
            int r = Interop.Kernel32.WriteFile(outErrHandle, &junkByte, 0, out _, IntPtr.Zero);
            return r != 0; // In Win32 apps w/ no console, bResult should be 0 for failure.
        }

        public static SafeFileHandle OpenStandardInputHandle() => OpenStandardHandle(Interop.Kernel32.HandleTypes.STD_INPUT_HANDLE);

        public static SafeFileHandle OpenStandardOutputHandle() => OpenStandardHandle(Interop.Kernel32.HandleTypes.STD_OUTPUT_HANDLE);

        public static SafeFileHandle OpenStandardErrorHandle() => OpenStandardHandle(Interop.Kernel32.HandleTypes.STD_ERROR_HANDLE);

        private static SafeFileHandle OpenStandardHandle(int handleType)
        {
            IntPtr handle = Interop.Kernel32.GetStdHandle(handleType);
            return new SafeFileHandle(handle, ownsHandle: false);
        }

        public static Encoding InputEncoding
        {
            get { return EncodingHelper.GetSupportedConsoleEncoding((int)Interop.Kernel32.GetConsoleCP()); }
        }

        public static void SetConsoleInputEncoding(Encoding enc)
        {
            if (enc.CodePage != UnicodeCodePage)
            {
                if (!Interop.Kernel32.SetConsoleCP(enc.CodePage))
                {
                    HandleSetConsoleEncodingError(Marshal.GetLastPInvokeError());
                }
            }
        }

        public static Encoding OutputEncoding
        {
            get { return EncodingHelper.GetSupportedConsoleEncoding((int)Interop.Kernel32.GetConsoleOutputCP()); }
        }

        public static void SetConsoleOutputEncoding(Encoding enc)
        {
            if (enc.CodePage != UnicodeCodePage)
            {