System.ConsolePal.RefreshColors C# (CSharp) Method

RefreshColors() private static method

Refreshes the foreground and background colors in use by the terminal by resetting the colors and then reissuing commands for both foreground and background, if necessary. Before doing so, the toChange ref is changed to value if value is valid.
private static RefreshColors ( ConsoleColor &toChange, ConsoleColor value ) : void
toChange ConsoleColor
value ConsoleColor
return void
        private static void RefreshColors(ref ConsoleColor toChange, ConsoleColor value)
        {
            if (((int)value & ~0xF) != 0 && value != Console.UnknownColor)
            {
                throw new ArgumentException(SR.Arg_InvalidConsoleColor);
            }

            lock (Console.Out)
            {
                toChange = value; // toChange is either s_trackedForegroundColor or s_trackedBackgroundColor

                WriteResetColorString();

                if (s_trackedForegroundColor != Console.UnknownColor)
                {
                    WriteSetColorString(foreground: true, color: s_trackedForegroundColor);
                }

                if (s_trackedBackgroundColor != Console.UnknownColor)
                {
                    WriteSetColorString(foreground: false, color: s_trackedBackgroundColor);
                }
            }
        }