717 {
718 if (sourceForeColor < ConsoleColor.Black || sourceForeColor >
ConsoleColor.White)
719 {
721 }
722 if (sourceBackColor < ConsoleColor.Black || sourceBackColor >
ConsoleColor.White)
723 {
725 }
726 global::Interop.Kernel32.COORD dwSize =
GetBufferInfo().dwSize;
727 if (sourceLeft < 0 || sourceLeft > dwSize.X)
728 {
730 }
731 if (sourceTop < 0 || sourceTop > dwSize.Y)
732 {
734 }
735 if (sourceWidth < 0 || sourceWidth > dwSize.X - sourceLeft)
736 {
738 }
739 if (sourceHeight < 0 || sourceTop > dwSize.Y - sourceHeight)
740 {
742 }
743 if (targetLeft < 0 || targetLeft > dwSize.X)
744 {
746 }
747 if (targetTop < 0 || targetTop > dwSize.Y)
748 {
750 }
751 if (sourceWidth == 0 || sourceHeight == 0)
752 {
753 return;
754 }
755 global::Interop.Kernel32.CHAR_INFO[]
array =
new global::Interop.Kernel32.CHAR_INFO[sourceWidth * sourceHeight];
756 dwSize.X = (
short)sourceWidth;
757 dwSize.Y = (
short)sourceHeight;
758 global::Interop.Kernel32.COORD bufferCoord = default(global::Interop.Kernel32.COORD);
759 global::Interop.Kernel32.SMALL_RECT readRegion = default(global::Interop.Kernel32.SMALL_RECT);
760 readRegion.Left = (
short)sourceLeft;
761 readRegion.Right = (
short)(sourceLeft + sourceWidth - 1);
762 readRegion.Top = (
short)sourceTop;
763 readRegion.Bottom = (
short)(sourceTop + sourceHeight - 1);
764 bool flag;
765 fixed (global::Interop.Kernel32.CHAR_INFO* pBuffer =
array)
766 {
767 flag = global::Interop.Kernel32.ReadConsoleOutput(
OutputHandle, pBuffer, dwSize, bufferCoord, ref readRegion);
768 }
769 if (!flag)
770 {
772 }
773 global::Interop.Kernel32.COORD cOORD = default(global::Interop.Kernel32.COORD);
774 cOORD.X = (
short)sourceLeft;
777 short wColorAttribute = (
short)color;
778 for (
int i = sourceTop;
i < sourceTop + sourceHeight;
i++)
779 {
781 if (!global::Interop.Kernel32.FillConsoleOutputCharacter(
OutputHandle, sourceChar, sourceWidth, cOORD, out var pNumCharsWritten))
782 {
784 }
785 if (!global::Interop.Kernel32.FillConsoleOutputAttribute(
OutputHandle, wColorAttribute, sourceWidth, cOORD, out pNumCharsWritten))
786 {
788 }
789 }
790 global::Interop.Kernel32.SMALL_RECT writeRegion = default(global::Interop.Kernel32.SMALL_RECT);
791 writeRegion.Left = (
short)targetLeft;
792 writeRegion.Right = (
short)(targetLeft + sourceWidth);
793 writeRegion.Top = (
short)targetTop;
794 writeRegion.Bottom = (
short)(targetTop + sourceHeight);
795 fixed (global::Interop.Kernel32.CHAR_INFO*
buffer =
array)
796 {
797 global::Interop.Kernel32.WriteConsoleOutput(
OutputHandle,
buffer, dwSize, bufferCoord, ref writeRegion);
798 }
799 }
static global::Interop.Kernel32.Color ConsoleColorToColorAttribute(ConsoleColor color, bool isBackground)
static IntPtr OutputHandle
static global::Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO GetBufferInfo()
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static int GetLastPInvokeError()
static string ArgumentOutOfRange_ConsoleBufferBoundaries
static string Arg_InvalidConsoleColor