Nullable annotate System.Drawing.Common (#31716)
authorEirik Tsarpalis <eirik.tsarpalis@gmail.com>
Wed, 26 Feb 2020 10:44:25 +0000 (10:44 +0000)
committerGitHub <noreply@github.com>
Wed, 26 Feb 2020 10:44:25 +0000 (10:44 +0000)
* Nullable annotate System.Drawing.Common

* Annotate unix files

* add removed attributes

* fix rebase issue

* address feedback

* add missing annotation

* address feedback

* address feedback

* address more feedback

98 files changed:
src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateDC.cs
src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateIC.cs
src/libraries/Common/src/Interop/Windows/Ole32/Interop.STATSTG.cs
src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs
src/libraries/System.Drawing.Common/ref/System.Drawing.Common.csproj
src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj
src/libraries/System.Drawing.Common/src/System/Drawing/Bitmap.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Bitmap.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Brushes.cs
src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphics.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphics.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphics.cs
src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphicsContext.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphicsContext.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphicsContext.cs
src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphicsManager.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/CharacterRange.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ClientUtils.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Design/CategoryNameCollection.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/CustomLineCap.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/GraphicsPath.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/GraphicsPath.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/GraphicsPathIterator.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/LinearGradientBrush.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/Matrix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/PathData.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Font.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs
src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Gdiplus.cs
src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs
src/libraries/System.Drawing.Common/src/System/Drawing/GraphicsContext.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Image.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Image.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ImageInfo.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/EncoderParameters.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/FrameDimension.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageAttributes.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageCodecInfo.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeader.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderEmf.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/PropertyItem.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Internal/SystemColorTracker.cs
src/libraries/System.Drawing.Common/src/System/Drawing/MarshallingHelpers.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Pen.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Pen.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Pens.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/DefaultPrintController.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/InvalidPrinterException.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/Margins.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PageSettings.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PageSettings.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PreviewPrintController.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PreviewPrintController.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintController.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintController.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintDocument.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintDocument.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintEventArgs.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintPageEventArgs.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintPageEventArgs.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrinterSettings.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrinterSettings.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/StandardPrintController.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/TriState.cs
src/libraries/System.Drawing.Common/src/System/Drawing/PropertyItemInternal.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Region.cs
src/libraries/System.Drawing.Common/src/System/Drawing/SystemBrushes.cs
src/libraries/System.Drawing.Common/src/System/Drawing/SystemFonts.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/SystemFonts.cs
src/libraries/System.Drawing.Common/src/System/Drawing/SystemIcons.Windows.cs
src/libraries/System.Drawing.Common/src/System/Drawing/SystemPens.cs
src/libraries/System.Drawing.Common/src/System/Drawing/TextureBrush.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.cs
src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs
src/libraries/System.Drawing.Common/src/misc/DpiHelper.cs
src/libraries/System.Drawing.Common/src/misc/GDI/DeviceContext.cs
src/libraries/System.Drawing.Common/src/misc/GDI/DeviceContexts.cs
src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs

index 209f436..f2431db 100644 (file)
@@ -5,11 +5,13 @@
 using System;
 using System.Runtime.InteropServices;
 
+#nullable enable
+
 internal static partial class Interop
 {
     internal static partial class Gdi32
     {
         [DllImport(Libraries.Gdi32, ExactSpelling = true, CharSet = CharSet.Unicode)]
-        public static extern IntPtr CreateDCW(string pwszDriver, string pwszDevice, string pszPort, IntPtr pdm);
+        public static extern IntPtr CreateDCW(string pwszDriver, string pwszDevice, string? pszPort, IntPtr pdm);
     }
 }
index f4176dd..1c1d831 100644 (file)
@@ -5,11 +5,13 @@
 using System;
 using System.Runtime.InteropServices;
 
+#nullable enable
+
 internal static partial class Interop
 {
     internal static partial class Gdi32
     {
         [DllImport(Libraries.Gdi32, ExactSpelling = true, CharSet = CharSet.Unicode)]
-        public static extern IntPtr CreateICW(string pszDriver, string pszDevice, string pszPort, IntPtr pdm);
+        public static extern IntPtr CreateICW(string pszDriver, string pszDevice, string? pszPort, IntPtr pdm);
     }
 }
index 2331531..dc9cead 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices.ComTypes;
@@ -60,7 +61,7 @@ internal static partial class Interop
             public uint grfStateBits;
             public uint reserved;
 
-            public string GetName() => Marshal.PtrToStringUni(pwcsName);
+            public string? GetName() => Marshal.PtrToStringUni(pwcsName);
 
             /// <summary>
             /// Caller is responsible for freeing the name memory.
@@ -76,7 +77,7 @@ internal static partial class Interop
             /// <summary>
             /// Callee is repsonsible for allocating the name memory.
             /// </summary>
-            public void AllocName(string name)
+            public void AllocName(string? name)
             {
                 pwcsName = Marshal.StringToCoTaskMemUni(name);
             }
index 35b2277..6e05c9b 100644 (file)
@@ -210,7 +210,7 @@ namespace System.Drawing
         public void Dispose() { }
         ~BufferedGraphics() { }
         public void Render() { }
-        public void Render(System.Drawing.Graphics target) { }
+        public void Render(System.Drawing.Graphics? target) { }
         public void Render(System.IntPtr targetDC) { }
     }
     public sealed partial class BufferedGraphicsContext : System.IDisposable
@@ -233,7 +233,7 @@ namespace System.Drawing
         public CharacterRange(int First, int Length) { throw null; }
         public int First { get { throw null; } set { } }
         public int Length { get { throw null; } set { } }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public static bool operator ==(System.Drawing.CharacterRange cr1, System.Drawing.CharacterRange cr2) { throw null; }
         public static bool operator !=(System.Drawing.CharacterRange cr1, System.Drawing.CharacterRange cr2) { throw null; }
@@ -320,7 +320,7 @@ namespace System.Drawing
         public System.Drawing.GraphicsUnit Unit { get { throw null; } }
         public object Clone() { throw null; }
         public void Dispose() { }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         ~Font() { }
         public static System.Drawing.Font FromHdc(System.IntPtr hdc) { throw null; }
         public static System.Drawing.Font FromHfont(System.IntPtr hfont) { throw null; }
@@ -340,14 +340,14 @@ namespace System.Drawing
     {
         public FontFamily(System.Drawing.Text.GenericFontFamilies genericFamily) { }
         public FontFamily(string name) { }
-        public FontFamily(string name, System.Drawing.Text.FontCollection fontCollection) { }
+        public FontFamily(string name, System.Drawing.Text.FontCollection? fontCollection) { }
         public static System.Drawing.FontFamily[] Families { get { throw null; } }
         public static System.Drawing.FontFamily GenericMonospace { get { throw null; } }
         public static System.Drawing.FontFamily GenericSansSerif { get { throw null; } }
         public static System.Drawing.FontFamily GenericSerif { get { throw null; } }
         public string Name { get { throw null; } }
         public void Dispose() { }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         ~FontFamily() { }
         public int GetCellAscent(System.Drawing.FontStyle style) { throw null; }
         public int GetCellDescent(System.Drawing.FontStyle style) { throw null; }
@@ -431,24 +431,24 @@ namespace System.Drawing
         public void DrawImage(System.Drawing.Image image, System.Drawing.PointF point) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.PointF[] destPoints) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback, int callbackData) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback, int callbackData) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.Point[] destPoints) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback, int callbackData) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback, int callbackData) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle rect) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs, System.Drawing.Graphics.DrawImageAbort callback, System.IntPtr callbackData) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs, System.Drawing.Graphics.DrawImageAbort? callback, System.IntPtr callbackData) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs, System.Drawing.Graphics.DrawImageAbort callback) { }
-        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs, System.Drawing.Graphics.DrawImageAbort callback, System.IntPtr callbackData) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs, System.Drawing.Graphics.DrawImageAbort? callback) { }
+        public void DrawImage(System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs, System.Drawing.Graphics.DrawImageAbort? callback, System.IntPtr callbackData) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.RectangleF rect) { }
         public void DrawImage(System.Drawing.Image image, System.Drawing.RectangleF destRect, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit) { }
         public void DrawImage(System.Drawing.Image image, int x, int y) { }
@@ -480,49 +480,49 @@ namespace System.Drawing
         public void DrawRectangle(System.Drawing.Pen pen, float x, float y, float width, float height) { }
         public void DrawRectangles(System.Drawing.Pen pen, System.Drawing.RectangleF[] rects) { }
         public void DrawRectangles(System.Drawing.Pen pen, System.Drawing.Rectangle[] rects) { }
-        public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point) { }
-        public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point, System.Drawing.StringFormat format) { }
-        public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle) { }
-        public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle, System.Drawing.StringFormat format) { }
-        public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y) { }
-        public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y, System.Drawing.StringFormat format) { }
+        public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point) { }
+        public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.PointF point, System.Drawing.StringFormat? format) { }
+        public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle) { }
+        public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, System.Drawing.RectangleF layoutRectangle, System.Drawing.StringFormat? format) { }
+        public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y) { }
+        public void DrawString(string? s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y, System.Drawing.StringFormat? format) { }
         public void EndContainer(System.Drawing.Drawing2D.GraphicsContainer container) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point destPoint, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point destPoint, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point destPoint, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point destPoint, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point destPoint, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point destPoint, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point destPoint, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point destPoint, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF destPoint, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF destPoint, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF destPoint, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF destPoint, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF destPoint, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF destPoint, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF destPoint, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF destPoint, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF[] destPoints, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF[] destPoints, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF[] destPoints, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF[] destPoints, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point[] destPoints, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point[] destPoints, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point[] destPoints, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point[] destPoints, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Rectangle destRect, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Rectangle destRect, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Rectangle destRect, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Rectangle destRect, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Rectangle destRect, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Rectangle destRect, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Rectangle destRect, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.Rectangle destRect, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.RectangleF destRect, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.RectangleF destRect, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.RectangleF destRect, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.RectangleF destRect, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.RectangleF destRect, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback) { }
         public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.RectangleF destRect, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData) { }
-        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.RectangleF destRect, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public void EnumerateMetafile(System.Drawing.Imaging.Metafile metafile, System.Drawing.RectangleF destRect, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit unit, System.Drawing.Graphics.EnumerateMetafileProc callback, System.IntPtr callbackData, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public void ExcludeClip(System.Drawing.Rectangle rect) { }
         public void ExcludeClip(System.Drawing.Region region) { }
         public void FillClosedCurve(System.Drawing.Brush brush, System.Drawing.PointF[] points) { }
@@ -580,14 +580,14 @@ namespace System.Drawing
         public bool IsVisible(int x, int y, int width, int height) { throw null; }
         public bool IsVisible(float x, float y) { throw null; }
         public bool IsVisible(float x, float y, float width, float height) { throw null; }
-        public System.Drawing.Region[] MeasureCharacterRanges(string text, System.Drawing.Font font, System.Drawing.RectangleF layoutRect, System.Drawing.StringFormat stringFormat) { throw null; }
-        public System.Drawing.SizeF MeasureString(string text, System.Drawing.Font font) { throw null; }
-        public System.Drawing.SizeF MeasureString(string text, System.Drawing.Font font, System.Drawing.PointF origin, System.Drawing.StringFormat stringFormat) { throw null; }
-        public System.Drawing.SizeF MeasureString(string text, System.Drawing.Font font, System.Drawing.SizeF layoutArea) { throw null; }
-        public System.Drawing.SizeF MeasureString(string text, System.Drawing.Font font, System.Drawing.SizeF layoutArea, System.Drawing.StringFormat stringFormat) { throw null; }
-        public System.Drawing.SizeF MeasureString(string text, System.Drawing.Font font, System.Drawing.SizeF layoutArea, System.Drawing.StringFormat stringFormat, out int charactersFitted, out int linesFilled) { throw null; }
-        public System.Drawing.SizeF MeasureString(string text, System.Drawing.Font font, int width) { throw null; }
-        public System.Drawing.SizeF MeasureString(string text, System.Drawing.Font font, int width, System.Drawing.StringFormat format) { throw null; }
+        public System.Drawing.Region[] MeasureCharacterRanges(string? text, System.Drawing.Font font, System.Drawing.RectangleF layoutRect, System.Drawing.StringFormat? stringFormat) { throw null; }
+        public System.Drawing.SizeF MeasureString(string? text, System.Drawing.Font font) { throw null; }
+        public System.Drawing.SizeF MeasureString(string? text, System.Drawing.Font font, System.Drawing.PointF origin, System.Drawing.StringFormat? stringFormat) { throw null; }
+        public System.Drawing.SizeF MeasureString(string? text, System.Drawing.Font font, System.Drawing.SizeF layoutArea) { throw null; }
+        public System.Drawing.SizeF MeasureString(string? text, System.Drawing.Font font, System.Drawing.SizeF layoutArea, System.Drawing.StringFormat? stringFormat) { throw null; }
+        public System.Drawing.SizeF MeasureString(string? text, System.Drawing.Font font, System.Drawing.SizeF layoutArea, System.Drawing.StringFormat? stringFormat, out int charactersFitted, out int linesFilled) { throw null; }
+        public System.Drawing.SizeF MeasureString(string? text, System.Drawing.Font font, int width) { throw null; }
+        public System.Drawing.SizeF MeasureString(string? text, System.Drawing.Font font, int width, System.Drawing.StringFormat? format) { throw null; }
         public void MultiplyTransform(System.Drawing.Drawing2D.Matrix matrix) { }
         public void MultiplyTransform(System.Drawing.Drawing2D.Matrix matrix, System.Drawing.Drawing2D.MatrixOrder order) { }
         public void ReleaseHdc() { }
@@ -654,7 +654,7 @@ namespace System.Drawing
         public int Width { get { throw null; } }
         public object Clone() { throw null; }
         public void Dispose() { }
-        public static System.Drawing.Icon ExtractAssociatedIcon(string filePath) { throw null; }
+        public static System.Drawing.Icon? ExtractAssociatedIcon(string filePath) { throw null; }
         ~Icon() { }
         public static System.Drawing.Icon FromHandle(System.IntPtr handle) { throw null; }
         public void Save(System.IO.Stream outputStream) { }
@@ -695,7 +695,7 @@ namespace System.Drawing
         public System.Drawing.Size Size { get { throw null; } }
         [System.ComponentModel.DefaultValueAttribute(null)]
         [System.ComponentModel.LocalizableAttribute(false)]
-        public object Tag { get { throw null; } set { } }
+        public object? Tag { get { throw null; } set { } }
         public float VerticalResolution { get { throw null; } }
         [System.ComponentModel.BrowsableAttribute(false)]
         [System.ComponentModel.DefaultValueAttribute(false)]
@@ -713,23 +713,23 @@ namespace System.Drawing
         public static System.Drawing.Image FromStream(System.IO.Stream stream, bool useEmbeddedColorManagement) { throw null; }
         public static System.Drawing.Image FromStream(System.IO.Stream stream, bool useEmbeddedColorManagement, bool validateImageData) { throw null; }
         public System.Drawing.RectangleF GetBounds(ref System.Drawing.GraphicsUnit pageUnit) { throw null; }
-        public System.Drawing.Imaging.EncoderParameters GetEncoderParameterList(System.Guid encoder) { throw null; }
+        public System.Drawing.Imaging.EncoderParameters? GetEncoderParameterList(System.Guid encoder) { throw null; }
         public int GetFrameCount(System.Drawing.Imaging.FrameDimension dimension) { throw null; }
         public static int GetPixelFormatSize(System.Drawing.Imaging.PixelFormat pixfmt) { throw null; }
-        public System.Drawing.Imaging.PropertyItem GetPropertyItem(int propid) { throw null; }
-        public System.Drawing.Image GetThumbnailImage(int thumbWidth, int thumbHeight, System.Drawing.Image.GetThumbnailImageAbort callback, System.IntPtr callbackData) { throw null; }
+        public System.Drawing.Imaging.PropertyItem? GetPropertyItem(int propid) { throw null; }
+        public System.Drawing.Image GetThumbnailImage(int thumbWidth, int thumbHeight, System.Drawing.Image.GetThumbnailImageAbort? callback, System.IntPtr callbackData) { throw null; }
         public static bool IsAlphaPixelFormat(System.Drawing.Imaging.PixelFormat pixfmt) { throw null; }
         public static bool IsCanonicalPixelFormat(System.Drawing.Imaging.PixelFormat pixfmt) { throw null; }
         public static bool IsExtendedPixelFormat(System.Drawing.Imaging.PixelFormat pixfmt) { throw null; }
         public void RemovePropertyItem(int propid) { }
         public void RotateFlip(System.Drawing.RotateFlipType rotateFlipType) { }
-        public void Save(System.IO.Stream stream, System.Drawing.Imaging.ImageCodecInfo encoder, System.Drawing.Imaging.EncoderParameters encoderParams) { }
+        public void Save(System.IO.Stream stream, System.Drawing.Imaging.ImageCodecInfo encoder, System.Drawing.Imaging.EncoderParameters? encoderParams) { }
         public void Save(System.IO.Stream stream, System.Drawing.Imaging.ImageFormat format) { }
         public void Save(string filename) { }
-        public void Save(string filename, System.Drawing.Imaging.ImageCodecInfo encoder, System.Drawing.Imaging.EncoderParameters encoderParams) { }
+        public void Save(string filename, System.Drawing.Imaging.ImageCodecInfo encoder, System.Drawing.Imaging.EncoderParameters? encoderParams) { }
         public void Save(string filename, System.Drawing.Imaging.ImageFormat format) { }
-        public void SaveAdd(System.Drawing.Image image, System.Drawing.Imaging.EncoderParameters encoderParams) { }
-        public void SaveAdd(System.Drawing.Imaging.EncoderParameters encoderParams) { }
+        public void SaveAdd(System.Drawing.Image image, System.Drawing.Imaging.EncoderParameters? encoderParams) { }
+        public void SaveAdd(System.Drawing.Imaging.EncoderParameters? encoderParams) { }
         public int SelectActiveFrame(System.Drawing.Imaging.FrameDimension dimension, int frameIndex) { throw null; }
         public void SetPropertyItem(System.Drawing.Imaging.PropertyItem propitem) { }
         void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
@@ -739,7 +739,7 @@ namespace System.Drawing
     {
         internal ImageAnimator() { }
         public static void Animate(System.Drawing.Image image, System.EventHandler onFrameChangedHandler) { }
-        public static bool CanAnimate(System.Drawing.Image image) { throw null; }
+        public static bool CanAnimate(System.Drawing.Image? image) { throw null; }
         public static void StopAnimate(System.Drawing.Image image, System.EventHandler onFrameChangedHandler) { }
         public static void UpdateFrames() { }
         public static void UpdateFrames(System.Drawing.Image image) { }
@@ -947,7 +947,7 @@ namespace System.Drawing
         public static System.Drawing.Region FromHrgn(System.IntPtr hrgn) { throw null; }
         public System.Drawing.RectangleF GetBounds(System.Drawing.Graphics g) { throw null; }
         public System.IntPtr GetHrgn(System.Drawing.Graphics g) { throw null; }
-        public System.Drawing.Drawing2D.RegionData GetRegionData() { throw null; }
+        public System.Drawing.Drawing2D.RegionData? GetRegionData() { throw null; }
         public System.Drawing.RectangleF[] GetRegionScans(System.Drawing.Drawing2D.Matrix matrix) { throw null; }
         public void Intersect(System.Drawing.Drawing2D.GraphicsPath path) { }
         public void Intersect(System.Drawing.Rectangle rect) { }
@@ -956,20 +956,20 @@ namespace System.Drawing
         public bool IsEmpty(System.Drawing.Graphics g) { throw null; }
         public bool IsInfinite(System.Drawing.Graphics g) { throw null; }
         public bool IsVisible(System.Drawing.Point point) { throw null; }
-        public bool IsVisible(System.Drawing.Point point, System.Drawing.Graphics g) { throw null; }
+        public bool IsVisible(System.Drawing.Point point, System.Drawing.Graphics? g) { throw null; }
         public bool IsVisible(System.Drawing.PointF point) { throw null; }
-        public bool IsVisible(System.Drawing.PointF point, System.Drawing.Graphics g) { throw null; }
+        public bool IsVisible(System.Drawing.PointF point, System.Drawing.Graphics? g) { throw null; }
         public bool IsVisible(System.Drawing.Rectangle rect) { throw null; }
-        public bool IsVisible(System.Drawing.Rectangle rect, System.Drawing.Graphics g) { throw null; }
+        public bool IsVisible(System.Drawing.Rectangle rect, System.Drawing.Graphics? g) { throw null; }
         public bool IsVisible(System.Drawing.RectangleF rect) { throw null; }
-        public bool IsVisible(System.Drawing.RectangleF rect, System.Drawing.Graphics g) { throw null; }
+        public bool IsVisible(System.Drawing.RectangleF rect, System.Drawing.Graphics? g) { throw null; }
         public bool IsVisible(int x, int y, System.Drawing.Graphics g) { throw null; }
         public bool IsVisible(int x, int y, int width, int height) { throw null; }
-        public bool IsVisible(int x, int y, int width, int height, System.Drawing.Graphics g) { throw null; }
+        public bool IsVisible(int x, int y, int width, int height, System.Drawing.Graphics? g) { throw null; }
         public bool IsVisible(float x, float y) { throw null; }
-        public bool IsVisible(float x, float y, System.Drawing.Graphics g) { throw null; }
+        public bool IsVisible(float x, float y, System.Drawing.Graphics? g) { throw null; }
         public bool IsVisible(float x, float y, float width, float height) { throw null; }
-        public bool IsVisible(float x, float y, float width, float height, System.Drawing.Graphics g) { throw null; }
+        public bool IsVisible(float x, float y, float width, float height, System.Drawing.Graphics? g) { throw null; }
         public void MakeEmpty() { }
         public void MakeInfinite() { }
         public void ReleaseHrgn(System.IntPtr regionHandle) { }
@@ -1120,15 +1120,15 @@ namespace System.Drawing
     }
     public static partial class SystemFonts
     {
-        public static System.Drawing.Font CaptionFont { get { throw null; } }
+        public static System.Drawing.Font? CaptionFont { get { throw null; } }
         public static System.Drawing.Font DefaultFont { get { throw null; } }
         public static System.Drawing.Font DialogFont { get { throw null; } }
-        public static System.Drawing.Font IconTitleFont { get { throw null; } }
-        public static System.Drawing.Font MenuFont { get { throw null; } }
-        public static System.Drawing.Font MessageBoxFont { get { throw null; } }
-        public static System.Drawing.Font SmallCaptionFont { get { throw null; } }
-        public static System.Drawing.Font StatusFont { get { throw null; } }
-        public static System.Drawing.Font GetFontByName(string systemFontName) { throw null; }
+        public static System.Drawing.Font? IconTitleFont { get { throw null; } }
+        public static System.Drawing.Font? MenuFont { get { throw null; } }
+        public static System.Drawing.Font? MessageBoxFont { get { throw null; } }
+        public static System.Drawing.Font? SmallCaptionFont { get { throw null; } }
+        public static System.Drawing.Font? StatusFont { get { throw null; } }
+        public static System.Drawing.Font? GetFontByName(string systemFontName) { throw null; }
     }
     public static partial class SystemIcons
     {
@@ -1187,9 +1187,9 @@ namespace System.Drawing
         public TextureBrush(System.Drawing.Image image, System.Drawing.Drawing2D.WrapMode wrapMode, System.Drawing.Rectangle dstRect) { }
         public TextureBrush(System.Drawing.Image image, System.Drawing.Drawing2D.WrapMode wrapMode, System.Drawing.RectangleF dstRect) { }
         public TextureBrush(System.Drawing.Image image, System.Drawing.Rectangle dstRect) { }
-        public TextureBrush(System.Drawing.Image image, System.Drawing.Rectangle dstRect, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public TextureBrush(System.Drawing.Image image, System.Drawing.Rectangle dstRect, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public TextureBrush(System.Drawing.Image image, System.Drawing.RectangleF dstRect) { }
-        public TextureBrush(System.Drawing.Image image, System.Drawing.RectangleF dstRect, System.Drawing.Imaging.ImageAttributes imageAttr) { }
+        public TextureBrush(System.Drawing.Image image, System.Drawing.RectangleF dstRect, System.Drawing.Imaging.ImageAttributes? imageAttr) { }
         public System.Drawing.Image Image { get { throw null; } }
         public System.Drawing.Drawing2D.Matrix Transform { get { throw null; } set { } }
         public System.Drawing.Drawing2D.WrapMode WrapMode { get { throw null; } set { } }
@@ -1211,14 +1211,14 @@ namespace System.Drawing
         public ToolboxBitmapAttribute(string imageFile) { }
         public ToolboxBitmapAttribute(System.Type t) { }
         public ToolboxBitmapAttribute(System.Type t, string name) { }
-        public override bool Equals(object value) { throw null; }
+        public override bool Equals(object? value) { throw null; }
         public override int GetHashCode() { throw null; }
-        public System.Drawing.Image GetImage(object component) { throw null; }
-        public System.Drawing.Image GetImage(object component, bool large) { throw null; }
-        public System.Drawing.Image GetImage(System.Type type) { throw null; }
-        public System.Drawing.Image GetImage(System.Type type, bool large) { throw null; }
-        public System.Drawing.Image GetImage(System.Type type, string imgName, bool large) { throw null; }
-        public static System.Drawing.Image GetImageFromResource(System.Type t, string imageName, bool large) { throw null; }
+        public System.Drawing.Image? GetImage(object? component) { throw null; }
+        public System.Drawing.Image? GetImage(object? component, bool large) { throw null; }
+        public System.Drawing.Image? GetImage(System.Type type) { throw null; }
+        public System.Drawing.Image? GetImage(System.Type type, bool large) { throw null; }
+        public System.Drawing.Image? GetImage(System.Type type, string? imgName, bool large) { throw null; }
+        public static System.Drawing.Image? GetImageFromResource(System.Type t, string? imageName, bool large) { throw null; }
     }
 }
 namespace System.Drawing.Design
@@ -1289,9 +1289,9 @@ namespace System.Drawing.Drawing2D
     }
     public partial class CustomLineCap : System.MarshalByRefObject, System.ICloneable, System.IDisposable
     {
-        public CustomLineCap(System.Drawing.Drawing2D.GraphicsPath fillPath, System.Drawing.Drawing2D.GraphicsPath strokePath) { }
-        public CustomLineCap(System.Drawing.Drawing2D.GraphicsPath fillPath, System.Drawing.Drawing2D.GraphicsPath strokePath, System.Drawing.Drawing2D.LineCap baseCap) { }
-        public CustomLineCap(System.Drawing.Drawing2D.GraphicsPath fillPath, System.Drawing.Drawing2D.GraphicsPath strokePath, System.Drawing.Drawing2D.LineCap baseCap, float baseInset) { }
+        public CustomLineCap(System.Drawing.Drawing2D.GraphicsPath? fillPath, System.Drawing.Drawing2D.GraphicsPath? strokePath) { }
+        public CustomLineCap(System.Drawing.Drawing2D.GraphicsPath? fillPath, System.Drawing.Drawing2D.GraphicsPath? strokePath, System.Drawing.Drawing2D.LineCap baseCap) { }
+        public CustomLineCap(System.Drawing.Drawing2D.GraphicsPath? fillPath, System.Drawing.Drawing2D.GraphicsPath? strokePath, System.Drawing.Drawing2D.LineCap baseCap, float baseInset) { }
         public System.Drawing.Drawing2D.LineCap BaseCap { get { throw null; } set { } }
         public float BaseInset { get { throw null; } set { } }
         public System.Drawing.Drawing2D.LineJoin StrokeJoin { get { throw null; } set { } }
@@ -1385,10 +1385,10 @@ namespace System.Drawing.Drawing2D
         public void AddRectangle(System.Drawing.RectangleF rect) { }
         public void AddRectangles(System.Drawing.RectangleF[] rects) { }
         public void AddRectangles(System.Drawing.Rectangle[] rects) { }
-        public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Point origin, System.Drawing.StringFormat format) { }
-        public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.PointF origin, System.Drawing.StringFormat format) { }
-        public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Rectangle layoutRect, System.Drawing.StringFormat format) { }
-        public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.RectangleF layoutRect, System.Drawing.StringFormat format) { }
+        public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Point origin, System.Drawing.StringFormat? format) { }
+        public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.PointF origin, System.Drawing.StringFormat? format) { }
+        public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.Rectangle layoutRect, System.Drawing.StringFormat? format) { }
+        public void AddString(string s, System.Drawing.FontFamily family, int style, float emSize, System.Drawing.RectangleF layoutRect, System.Drawing.StringFormat? format) { }
         public void ClearMarkers() { }
         public object Clone() { throw null; }
         public void CloseAllFigures() { }
@@ -1396,44 +1396,44 @@ namespace System.Drawing.Drawing2D
         public void Dispose() { }
         ~GraphicsPath() { }
         public void Flatten() { }
-        public void Flatten(System.Drawing.Drawing2D.Matrix matrix) { }
-        public void Flatten(System.Drawing.Drawing2D.Matrix matrix, float flatness) { }
+        public void Flatten(System.Drawing.Drawing2D.Matrix? matrix) { }
+        public void Flatten(System.Drawing.Drawing2D.Matrix? matrix, float flatness) { }
         public System.Drawing.RectangleF GetBounds() { throw null; }
-        public System.Drawing.RectangleF GetBounds(System.Drawing.Drawing2D.Matrix matrix) { throw null; }
-        public System.Drawing.RectangleF GetBounds(System.Drawing.Drawing2D.Matrix matrix, System.Drawing.Pen pen) { throw null; }
+        public System.Drawing.RectangleF GetBounds(System.Drawing.Drawing2D.Matrix? matrix) { throw null; }
+        public System.Drawing.RectangleF GetBounds(System.Drawing.Drawing2D.Matrix? matrix, System.Drawing.Pen? pen) { throw null; }
         public System.Drawing.PointF GetLastPoint() { throw null; }
         public bool IsOutlineVisible(System.Drawing.Point point, System.Drawing.Pen pen) { throw null; }
-        public bool IsOutlineVisible(System.Drawing.Point pt, System.Drawing.Pen pen, System.Drawing.Graphics graphics) { throw null; }
+        public bool IsOutlineVisible(System.Drawing.Point pt, System.Drawing.Pen pen, System.Drawing.Graphics? graphics) { throw null; }
         public bool IsOutlineVisible(System.Drawing.PointF point, System.Drawing.Pen pen) { throw null; }
-        public bool IsOutlineVisible(System.Drawing.PointF pt, System.Drawing.Pen pen, System.Drawing.Graphics graphics) { throw null; }
+        public bool IsOutlineVisible(System.Drawing.PointF pt, System.Drawing.Pen pen, System.Drawing.Graphics? graphics) { throw null; }
         public bool IsOutlineVisible(int x, int y, System.Drawing.Pen pen) { throw null; }
-        public bool IsOutlineVisible(int x, int y, System.Drawing.Pen pen, System.Drawing.Graphics graphics) { throw null; }
+        public bool IsOutlineVisible(int x, int y, System.Drawing.Pen pen, System.Drawing.Graphics? graphics) { throw null; }
         public bool IsOutlineVisible(float x, float y, System.Drawing.Pen pen) { throw null; }
-        public bool IsOutlineVisible(float x, float y, System.Drawing.Pen pen, System.Drawing.Graphics graphics) { throw null; }
+        public bool IsOutlineVisible(float x, float y, System.Drawing.Pen pen, System.Drawing.Graphics? graphics) { throw null; }
         public bool IsVisible(System.Drawing.Point point) { throw null; }
-        public bool IsVisible(System.Drawing.Point pt, System.Drawing.Graphics graphics) { throw null; }
+        public bool IsVisible(System.Drawing.Point pt, System.Drawing.Graphics? graphics) { throw null; }
         public bool IsVisible(System.Drawing.PointF point) { throw null; }
-        public bool IsVisible(System.Drawing.PointF pt, System.Drawing.Graphics graphics) { throw null; }
+        public bool IsVisible(System.Drawing.PointF pt, System.Drawing.Graphics? graphics) { throw null; }
         public bool IsVisible(int x, int y) { throw null; }
-        public bool IsVisible(int x, int y, System.Drawing.Graphics graphics) { throw null; }
+        public bool IsVisible(int x, int y, System.Drawing.Graphics? graphics) { throw null; }
         public bool IsVisible(float x, float y) { throw null; }
-        public bool IsVisible(float x, float y, System.Drawing.Graphics graphics) { throw null; }
+        public bool IsVisible(float x, float y, System.Drawing.Graphics? graphics) { throw null; }
         public void Reset() { }
         public void Reverse() { }
         public void SetMarkers() { }
         public void StartFigure() { }
         public void Transform(System.Drawing.Drawing2D.Matrix matrix) { }
         public void Warp(System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect) { }
-        public void Warp(System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.Drawing2D.Matrix matrix) { }
-        public void Warp(System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.Drawing2D.Matrix matrix, System.Drawing.Drawing2D.WarpMode warpMode) { }
-        public void Warp(System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.Drawing2D.Matrix matrix, System.Drawing.Drawing2D.WarpMode warpMode, float flatness) { }
+        public void Warp(System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.Drawing2D.Matrix? matrix) { }
+        public void Warp(System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.Drawing2D.Matrix? matrix, System.Drawing.Drawing2D.WarpMode warpMode) { }
+        public void Warp(System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.Drawing2D.Matrix? matrix, System.Drawing.Drawing2D.WarpMode warpMode, float flatness) { }
         public void Widen(System.Drawing.Pen pen) { }
-        public void Widen(System.Drawing.Pen pen, System.Drawing.Drawing2D.Matrix matrix) { }
-        public void Widen(System.Drawing.Pen pen, System.Drawing.Drawing2D.Matrix matrix, float flatness) { }
+        public void Widen(System.Drawing.Pen pen, System.Drawing.Drawing2D.Matrix? matrix) { }
+        public void Widen(System.Drawing.Pen pen, System.Drawing.Drawing2D.Matrix? matrix, float flatness) { }
     }
     public sealed partial class GraphicsPathIterator : System.MarshalByRefObject, System.IDisposable
     {
-        public GraphicsPathIterator(System.Drawing.Drawing2D.GraphicsPath path) { }
+        public GraphicsPathIterator(System.Drawing.Drawing2D.GraphicsPath? path) { }
         public int Count { get { throw null; } }
         public int SubpathCount { get { throw null; } }
         public int CopyData(ref System.Drawing.PointF[] points, ref byte[] types, int startIndex, int endIndex) { throw null; }
@@ -1542,7 +1542,7 @@ namespace System.Drawing.Drawing2D
         public LinearGradientBrush(System.Drawing.RectangleF rect, System.Drawing.Color color1, System.Drawing.Color color2, System.Drawing.Drawing2D.LinearGradientMode linearGradientMode) { }
         public LinearGradientBrush(System.Drawing.RectangleF rect, System.Drawing.Color color1, System.Drawing.Color color2, float angle) { }
         public LinearGradientBrush(System.Drawing.RectangleF rect, System.Drawing.Color color1, System.Drawing.Color color2, float angle, bool isAngleScaleable) { }
-        public System.Drawing.Drawing2D.Blend Blend { get { throw null; } set { } }
+        public System.Drawing.Drawing2D.Blend? Blend { get { throw null; } set { } }
         public bool GammaCorrection { get { throw null; } set { } }
         public System.Drawing.Drawing2D.ColorBlend InterpolationColors { get { throw null; } set { } }
         public System.Drawing.Color[] LinearColors { get { throw null; } set { } }
@@ -1605,7 +1605,7 @@ namespace System.Drawing.Drawing2D
         public float OffsetY { get { throw null; } }
         public System.Drawing.Drawing2D.Matrix Clone() { throw null; }
         public void Dispose() { }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         ~Matrix() { }
         public override int GetHashCode() { throw null; }
         public void Invert() { }
@@ -1636,8 +1636,8 @@ namespace System.Drawing.Drawing2D
     public sealed partial class PathData
     {
         public PathData() { }
-        public System.Drawing.PointF[] Points { get { throw null; } set { } }
-        public byte[] Types { get { throw null; } set { } }
+        public System.Drawing.PointF[]? Points { get { throw null; } set { } }
+        public byte[]? Types { get { throw null; } set { } }
     }
     public sealed partial class PathGradientBrush : System.Drawing.Brush
     {
@@ -2151,7 +2151,7 @@ namespace System.Drawing.Imaging
         ValueTypeRational = 5,
         ValueTypeLongRange = 6,
         ValueTypeUndefined = 7,
-        ValueTypeRationalRange = 8
+        ValueTypeRationalRange = 8,
     }
     public enum EncoderValue
     {
@@ -2187,7 +2187,7 @@ namespace System.Drawing.Imaging
         public static System.Drawing.Imaging.FrameDimension Page { get { throw null; } }
         public static System.Drawing.Imaging.FrameDimension Resolution { get { throw null; } }
         public static System.Drawing.Imaging.FrameDimension Time { get { throw null; } }
-        public override bool Equals(object o) { throw null; }
+        public override bool Equals(object? o) { throw null; }
         public override int GetHashCode() { throw null; }
         public override string ToString() { throw null; }
     }
@@ -2218,9 +2218,9 @@ namespace System.Drawing.Imaging
         public void SetBrushRemapTable(System.Drawing.Imaging.ColorMap[] map) { }
         public void SetColorKey(System.Drawing.Color colorLow, System.Drawing.Color colorHigh) { }
         public void SetColorKey(System.Drawing.Color colorLow, System.Drawing.Color colorHigh, System.Drawing.Imaging.ColorAdjustType type) { }
-        public void SetColorMatrices(System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrix grayMatrix) { }
-        public void SetColorMatrices(System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrix grayMatrix, System.Drawing.Imaging.ColorMatrixFlag flags) { }
-        public void SetColorMatrices(System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrix grayMatrix, System.Drawing.Imaging.ColorMatrixFlag mode, System.Drawing.Imaging.ColorAdjustType type) { }
+        public void SetColorMatrices(System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrix? grayMatrix) { }
+        public void SetColorMatrices(System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrix? grayMatrix, System.Drawing.Imaging.ColorMatrixFlag flags) { }
+        public void SetColorMatrices(System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrix? grayMatrix, System.Drawing.Imaging.ColorMatrixFlag mode, System.Drawing.Imaging.ColorAdjustType type) { }
         public void SetColorMatrix(System.Drawing.Imaging.ColorMatrix newColorMatrix) { }
         public void SetColorMatrix(System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrixFlag flags) { }
         public void SetColorMatrix(System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrixFlag mode, System.Drawing.Imaging.ColorAdjustType type) { }
@@ -2257,17 +2257,17 @@ namespace System.Drawing.Imaging
     {
         internal ImageCodecInfo() { }
         public System.Guid Clsid { get { throw null; } set { } }
-        public string CodecName { get { throw null; } set { } }
-        public string DllName { get { throw null; } set { } }
-        public string FilenameExtension { get { throw null; } set { } }
+        public string? CodecName { get { throw null; } set { } }
+        public string? DllName { get { throw null; } set { } }
+        public string? FilenameExtension { get { throw null; } set { } }
         public System.Drawing.Imaging.ImageCodecFlags Flags { get { throw null; } set { } }
-        public string FormatDescription { get { throw null; } set { } }
+        public string? FormatDescription { get { throw null; } set { } }
         public System.Guid FormatID { get { throw null; } set { } }
-        public string MimeType { get { throw null; } set { } }
+        public string? MimeType { get { throw null; } set { } }
         [System.CLSCompliantAttribute(false)]
-        public byte[][] SignatureMasks { get { throw null; } set { } }
+        public byte[][]? SignatureMasks { get { throw null; } set { } }
         [System.CLSCompliantAttribute(false)]
-        public byte[][] SignaturePatterns { get { throw null; } set { } }
+        public byte[][]? SignaturePatterns { get { throw null; } set { } }
         public int Version { get { throw null; } set { } }
         public static System.Drawing.Imaging.ImageCodecInfo[] GetImageDecoders() { throw null; }
         public static System.Drawing.Imaging.ImageCodecInfo[] GetImageEncoders() { throw null; }
@@ -2307,7 +2307,7 @@ namespace System.Drawing.Imaging
         public static System.Drawing.Imaging.ImageFormat Png { get { throw null; } }
         public static System.Drawing.Imaging.ImageFormat Tiff { get { throw null; } }
         public static System.Drawing.Imaging.ImageFormat Wmf { get { throw null; } }
-        public override bool Equals(object o) { throw null; }
+        public override bool Equals(object? o) { throw null; }
         public override int GetHashCode() { throw null; }
         public override string ToString() { throw null; }
     }
@@ -2322,43 +2322,43 @@ namespace System.Drawing.Imaging
     {
         public Metafile(System.IntPtr henhmetafile, bool deleteEmf) { }
         public Metafile(System.IntPtr referenceHdc, System.Drawing.Imaging.EmfType emfType) { }
-        public Metafile(System.IntPtr referenceHdc, System.Drawing.Imaging.EmfType emfType, string description) { }
+        public Metafile(System.IntPtr referenceHdc, System.Drawing.Imaging.EmfType emfType, string? description) { }
         public Metafile(System.IntPtr hmetafile, System.Drawing.Imaging.WmfPlaceableFileHeader wmfHeader) { }
         public Metafile(System.IntPtr hmetafile, System.Drawing.Imaging.WmfPlaceableFileHeader wmfHeader, bool deleteWmf) { }
         public Metafile(System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect) { }
         public Metafile(System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit) { }
         public Metafile(System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type) { }
-        public Metafile(System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string desc) { }
+        public Metafile(System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string? desc) { }
         public Metafile(System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect) { }
         public Metafile(System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit) { }
         public Metafile(System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type) { }
-        public Metafile(System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string description) { }
+        public Metafile(System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string? description) { }
         public Metafile(System.IO.Stream stream) { }
         public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc) { }
         public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.Imaging.EmfType type) { }
-        public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.Imaging.EmfType type, string description) { }
+        public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.Imaging.EmfType type, string? description) { }
         public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect) { }
         public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit) { }
         public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type) { }
-        public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string description) { }
+        public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string? description) { }
         public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect) { }
         public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit) { }
         public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type) { }
-        public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string description) { }
+        public Metafile(System.IO.Stream stream, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string? description) { }
         public Metafile(string filename) { }
         public Metafile(string fileName, System.IntPtr referenceHdc) { }
         public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Imaging.EmfType type) { }
-        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Imaging.EmfType type, string description) { }
+        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Imaging.EmfType type, string? description) { }
         public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect) { }
         public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit) { }
         public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type) { }
-        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string description) { }
-        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, string description) { }
+        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string? description) { }
+        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.Rectangle frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, string? description) { }
         public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect) { }
         public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit) { }
         public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type) { }
-        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string description) { }
-        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, string desc) { }
+        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, System.Drawing.Imaging.EmfType type, string? description) { }
+        public Metafile(string fileName, System.IntPtr referenceHdc, System.Drawing.RectangleF frameRect, System.Drawing.Imaging.MetafileFrameUnit frameUnit, string? desc) { }
         public System.IntPtr GetHenhmetafile() { throw null; }
         public System.Drawing.Imaging.MetafileHeader GetMetafileHeader() { throw null; }
         public static System.Drawing.Imaging.MetafileHeader GetMetafileHeader(System.IntPtr henhmetafile) { throw null; }
@@ -2458,7 +2458,7 @@ namespace System.Drawing.Imaging
         public int Id { get { throw null; } set { } }
         public int Len { get { throw null; } set { } }
         public short Type { get { throw null; } set { } }
-        public byte[] Value { get { throw null; } set { } }
+        public byte[]? Value { get { throw null; } set { } }
     }
     public sealed partial class WmfPlaceableFileHeader
     {
@@ -2501,7 +2501,7 @@ namespace System.Drawing.Printing
         public int Right { get { throw null; } set { } }
         public int Top { get { throw null; } set { } }
         public object Clone() { throw null; }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
         public static bool operator ==(System.Drawing.Printing.Margins m1, System.Drawing.Printing.Margins m2) { throw null; }
         public static bool operator !=(System.Drawing.Printing.Margins m1, System.Drawing.Printing.Margins m2) { throw null; }
@@ -2712,7 +2712,7 @@ namespace System.Drawing.Printing
         public virtual bool IsPreview { get { throw null; } }
         public virtual void OnEndPage(System.Drawing.Printing.PrintDocument document, System.Drawing.Printing.PrintPageEventArgs e) { }
         public virtual void OnEndPrint(System.Drawing.Printing.PrintDocument document, System.Drawing.Printing.PrintEventArgs e) { }
-        public virtual System.Drawing.Graphics OnStartPage(System.Drawing.Printing.PrintDocument document, System.Drawing.Printing.PrintPageEventArgs e) { throw null; }
+        public virtual System.Drawing.Graphics? OnStartPage(System.Drawing.Printing.PrintDocument document, System.Drawing.Printing.PrintPageEventArgs e) { throw null; }
         public virtual void OnStartPrint(System.Drawing.Printing.PrintDocument document, System.Drawing.Printing.PrintEventArgs e) { }
     }
     public partial class PrintDocument : System.ComponentModel.Component
@@ -2735,10 +2735,10 @@ namespace System.Drawing.Printing
         public event System.Drawing.Printing.PrintEventHandler EndPrint { add { } remove { } }
         public event System.Drawing.Printing.PrintPageEventHandler PrintPage { add { } remove { } }
         public event System.Drawing.Printing.QueryPageSettingsEventHandler QueryPageSettings { add { } remove { } }
-        protected virtual void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e) { }
-        protected virtual void OnEndPrint(System.Drawing.Printing.PrintEventArgs e) { }
-        protected virtual void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e) { }
-        protected virtual void OnQueryPageSettings(System.Drawing.Printing.QueryPageSettingsEventArgs e) { }
+        protected internal virtual void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e) { }
+        protected internal virtual void OnEndPrint(System.Drawing.Printing.PrintEventArgs e) { }
+        protected internal virtual void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e) { }
+        protected internal virtual void OnQueryPageSettings(System.Drawing.Printing.QueryPageSettingsEventArgs e) { }
         public void Print() { }
         public override string ToString() { throw null; }
     }
@@ -2883,9 +2883,9 @@ namespace System.Drawing.Printing
     public delegate void PrintEventHandler(object sender, System.Drawing.Printing.PrintEventArgs e);
     public partial class PrintPageEventArgs : System.EventArgs
     {
-        public PrintPageEventArgs(System.Drawing.Graphics graphics, System.Drawing.Rectangle marginBounds, System.Drawing.Rectangle pageBounds, System.Drawing.Printing.PageSettings pageSettings) { }
+        public PrintPageEventArgs(System.Drawing.Graphics? graphics, System.Drawing.Rectangle marginBounds, System.Drawing.Rectangle pageBounds, System.Drawing.Printing.PageSettings pageSettings) { }
         public bool Cancel { get { throw null; } set { } }
-        public System.Drawing.Graphics Graphics { get { throw null; } }
+        public System.Drawing.Graphics? Graphics { get { throw null; } }
         public bool HasMorePages { get { throw null; } set { } }
         public System.Drawing.Rectangle MarginBounds { get { throw null; } }
         public System.Drawing.Rectangle PageBounds { get { throw null; } }
index 85eed37..46ac878 100644 (file)
@@ -2,6 +2,7 @@
   <PropertyGroup>
     <TargetFrameworks>netcoreapp3.0;$(NetCoreAppCurrent)</TargetFrameworks>
     <ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="System.Drawing.Common.cs" />
index 51401ba..7a6ca38 100644 (file)
@@ -7,6 +7,7 @@
     <IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
     <TargetFrameworks>netcoreapp3.0-Windows_NT;netcoreapp3.0-Unix;$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix</TargetFrameworks>
     <ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="System\Drawing\Bitmap.cs" />
index 9599bd0..195e01a 100644 (file)
@@ -73,7 +73,7 @@ namespace System.Drawing
             if (type == null)
                 throw new NullReferenceException();
 
-            Stream s = type.GetTypeInfo().Assembly.GetManifestResourceStream(type, resource);
+            Stream? s = type.GetTypeInfo().Assembly.GetManifestResourceStream(type, resource);
             if (s == null)
             {
                 string msg = string.Format("Resource '{0}' was not found.", resource);
index 810dd48..c879bf7 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Drawing
     {
         public Bitmap(Type type, string resource)
         {
-            Stream stream = type.Module.Assembly.GetManifestResourceStream(type, resource);
+            Stream? stream = type.Module.Assembly.GetManifestResourceStream(type, resource);
             if (stream == null)
             {
                 throw new ArgumentException(SR.Format(SR.ResourceNotFound, type, resource));
index 303174d..06ccdf8 100644 (file)
@@ -20,8 +20,8 @@ namespace System.Drawing
         /// For performance, the suffix is cached in a static variable so it only has to be read
         /// once per appdomain.
         /// </remarks>
-        private static string s_suffix;
-        internal static string Suffix
+        private static string? s_suffix;
+        internal static string? Suffix
         {
             get
             {
@@ -72,9 +72,9 @@ namespace System.Drawing
         }
 
         // Calls assembly.GetManifestResourceStream in a try/catch and returns null if not found
-        private static Stream GetResourceStreamHelper(Assembly assembly, Type type, string name)
+        private static Stream? GetResourceStreamHelper(Assembly assembly, Type type, string name)
         {
-            Stream stream = null;
+            Stream? stream = null;
             try
             {
                 stream = assembly.GetManifestResourceStream(type, name);
@@ -90,7 +90,7 @@ namespace System.Drawing
             return DoesAssemblyHaveCustomAttribute(assembly, assembly.GetType(typeName));
         }
 
-        private static bool DoesAssemblyHaveCustomAttribute(Assembly assembly, Type attrType)
+        private static bool DoesAssemblyHaveCustomAttribute(Assembly assembly, Type? attrType)
         {
             if (attrType != null)
             {
@@ -140,7 +140,7 @@ namespace System.Drawing
         /// The manifest resource stream corresponding to <paramref name="originalName"/> with the
         /// current suffix applied; or if that is not found, the stream corresponding to <paramref name="originalName"/>.
         /// </returns>
-        public static Stream GetResourceStream(Assembly assembly, Type type, string originalName)
+        public static Stream? GetResourceStream(Assembly assembly, Type type, string originalName)
         {
             if (Suffix != string.Empty)
             {
@@ -150,7 +150,7 @@ namespace System.Drawing
                     if (SameAssemblyOptIn(assembly))
                     {
                         string newName = AppendSuffix(originalName);
-                        Stream stream = GetResourceStreamHelper(assembly, type, newName);
+                        Stream? stream = GetResourceStreamHelper(assembly, type, newName);
                         if (stream != null)
                         {
                             return stream;
@@ -173,7 +173,7 @@ namespace System.Drawing
                         Assembly satellite = Assembly.Load(assemblyName);
                         if (satellite != null)
                         {
-                            Stream stream = GetResourceStreamHelper(satellite, type, originalName);
+                            Stream? stream = GetResourceStreamHelper(satellite, type, originalName);
                             if (stream != null)
                             {
                                 return stream;
@@ -201,7 +201,7 @@ namespace System.Drawing
         /// The manifest resource stream corresponding to <paramref name="originalName"/> with the
         /// current suffix applied; or if that is not found, the stream corresponding to <paramref name="originalName"/>.
         /// </returns>
-        public static Stream GetResourceStream(Type type, string originalName)
+        public static Stream? GetResourceStream(Type type, string originalName)
         {
             return GetResourceStream(type.Module.Assembly, type, originalName);
         }
@@ -218,7 +218,7 @@ namespace System.Drawing
         /// </returns>
         public static Icon CreateIcon(Type type, string originalName)
         {
-            return new Icon(GetResourceStream(type, originalName));
+            return new Icon(GetResourceStream(type, originalName)!);
         }
 
         /// <summary>
@@ -233,7 +233,7 @@ namespace System.Drawing
         /// </returns>
         public static Bitmap CreateBitmap(Type type, string originalName)
         {
-            return new Bitmap(GetResourceStream(type, originalName));
+            return new Bitmap(GetResourceStream(type, originalName)!);
         }
     }
 }
index 6c53ac9..2c77b66 100644 (file)
@@ -313,7 +313,7 @@ namespace System.Drawing
 
         private static Brush GetBrush(object key, Color color)
         {
-            Brush brush = (Brush)Gdip.ThreadData[key];
+            Brush? brush = (Brush?)Gdip.ThreadData[key];
             if (brush == null)
             {
                 brush = new SolidBrush(color);
index c1e1fb3..c1c92c2 100644 (file)
@@ -37,10 +37,10 @@ namespace System.Drawing
     public sealed partial class BufferedGraphics
     {
         private Rectangle size;
-        private Bitmap membmp = null;
-        private Graphics source = null;
+        private Bitmap membmp;
+        private Graphics? source;
 
-        internal BufferedGraphics(Graphics targetGraphics, IntPtr targetDc, Rectangle targetRectangle)
+        internal BufferedGraphics(Graphics? targetGraphics, IntPtr targetDc, Rectangle targetRectangle)
         {
             _targetGraphics = targetGraphics;
             _targetDC = targetDc;
@@ -57,7 +57,7 @@ namespace System.Drawing
                     source = Graphics.FromImage(membmp);
                 }
 
-                return source;
+                return source!;
             }
         }
 
@@ -66,7 +66,7 @@ namespace System.Drawing
             if (membmp != null)
             {
                 membmp.Dispose();
-                membmp = null;
+                membmp = null!;
             }
 
             if (source != null)
@@ -78,7 +78,7 @@ namespace System.Drawing
             _targetGraphics = null;
         }
 
-        public void Render(Graphics target)
+        public void Render(Graphics? target)
         {
             if (target == null)
                 return;
index 4a4f9df..1c40554 100644 (file)
@@ -16,7 +16,7 @@ namespace System.Drawing
         /// <summary>
         /// Internal constructor, this class is created by BufferedGraphicsContext.
         /// </summary>
-        internal BufferedGraphics(Graphics bufferedGraphicsSurface, BufferedGraphicsContext context, Graphics targetGraphics,
+        internal BufferedGraphics(Graphics bufferedGraphicsSurface, BufferedGraphicsContext context, Graphics? targetGraphics,
                                   IntPtr targetDC, Point targetLoc, Size virtualSize)
         {
             _context = context;
@@ -36,14 +36,14 @@ namespace System.Drawing
                 if (DisposeContext)
                 {
                     _context.Dispose();
-                    _context = null;
+                    _context = null!;
                 }
             }
 
             if (_bufferedGraphicsSurface != null)
             {
                 _bufferedGraphicsSurface.Dispose();
-                _bufferedGraphicsSurface = null;
+                _bufferedGraphicsSurface = null!;
             }
         }
 
@@ -55,7 +55,7 @@ namespace System.Drawing
         /// <summary>
         /// Renders the buffer to the specified target graphics.
         /// </summary>
-        public void Render(Graphics target)
+        public void Render(Graphics? target)
         {
             if (target != null)
             {
index 0bc2824..f5db8a7 100644 (file)
@@ -14,7 +14,7 @@ namespace System.Drawing
     /// </summary>
     public sealed partial class BufferedGraphics : IDisposable
     {
-        private Graphics _targetGraphics;
+        private Graphics? _targetGraphics;
         private readonly IntPtr _targetDC;
 
         /// <summary>
index 27d772d..b37ba7a 100644 (file)
@@ -36,7 +36,7 @@ namespace System.Drawing
 {
     public sealed partial class BufferedGraphicsContext : IDisposable
     {
-        private BufferedGraphics AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
+        private BufferedGraphics AllocBuffer(Graphics? targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
         {
             BufferedGraphics graphics = new BufferedGraphics(targetGraphics, targetDC, targetRectangle);
             return graphics;
index 9177013..97896f6 100644 (file)
@@ -18,8 +18,8 @@ namespace System.Drawing
         private IntPtr _compatDC;
         private IntPtr _dib;
         private IntPtr _oldBitmap;
-        private Graphics _compatGraphics;
-        private BufferedGraphics _buffer;
+        private Graphics? _compatGraphics;
+        private BufferedGraphics? _buffer;
         private int _busy;
         private bool _invalidateWhenFree;
 
@@ -30,7 +30,7 @@ namespace System.Drawing
         /// <summary>
         /// Returns a BufferedGraphics that is matched for the specified target HDC object.
         /// </summary>
-        private BufferedGraphics AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
+        private BufferedGraphics AllocBuffer(Graphics? targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
         {
             int oldBusy = Interlocked.CompareExchange(ref _busy, BufferBusyPainting, BufferFree);
 
@@ -304,7 +304,7 @@ namespace System.Drawing
                 // Create the DIB section. Let Win32 allocate the memory and return
                 // a pointer to the bitmap surface.
                 hbmRet = SafeNativeMethods.CreateDIBSection(new HandleRef(null, hdc), ref pbmi, NativeMethods.DIB_RGB_COLORS, ref ppvBits, IntPtr.Zero, 0);
-                Win32Exception ex = null;
+                Win32Exception? ex = null;
                 if (hbmRet == IntPtr.Zero)
                 {
                     ex = new Win32Exception(Marshal.GetLastWin32Error());
index 19efb26..0098578 100644 (file)
@@ -82,10 +82,10 @@ namespace System.Drawing
         /// <summary>
         /// Returns a BufferedGraphics that is matched for the specified target HDC object.
         /// </summary>
-        private BufferedGraphics AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
+        private BufferedGraphics AllocBufferInTempManager(Graphics? targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
         {
-            BufferedGraphicsContext tempContext = null;
-            BufferedGraphics tempBuffer = null;
+            BufferedGraphicsContext? tempContext = null;
+            BufferedGraphics? tempBuffer = null;
 
             try
             {
index 0f6e01c..8700c4a 100644 (file)
@@ -30,6 +30,6 @@ namespace System.Drawing
         /// Called on process exit
         /// </summary>
         [PrePrepareMethod]
-        private static void OnShutdown(object sender, EventArgs e) => Current.Invalidate();
+        private static void OnShutdown(object? sender, EventArgs e) => Current.Invalidate();
     }
 }
index 46ede46..f99fd01 100644 (file)
@@ -40,7 +40,7 @@ namespace System.Drawing
             set => _length = value;
         }
 
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (!(obj is CharacterRange cr))
             {
index 615fd22..c9d7cfb 100644 (file)
@@ -4,6 +4,7 @@
 
 using System.Collections;
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 using System.Security;
 
 namespace System.Drawing
@@ -61,7 +62,7 @@ namespace System.Drawing
             /// </summary>
             public int RefCheckThreshold { get; set; } = int.MaxValue;
 
-            public object this[int index]
+            public object? this[int index]
             {
                 get
                 {
@@ -81,7 +82,7 @@ namespace System.Drawing
                 int currentCount = Count;
                 for (int i = 0; i < currentCount; i++)
                 {
-                    object item = this[currentIndex];
+                    object? item = this[currentIndex];
 
                     if (item == null)
                     {
@@ -95,7 +96,7 @@ namespace System.Drawing
                 }
             }
 
-            public override bool Equals(object obj)
+            public override bool Equals(object? obj)
             {
                 if (!(obj is WeakRefCollection other))
                 {
@@ -111,7 +112,8 @@ namespace System.Drawing
                 {
                     if (InnerList[i] != other.InnerList[i])
                     {
-                        if (InnerList[i] == null || !InnerList[i].Equals(other.InnerList[i]))
+                        // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
+                        if (InnerList[i] == null || !InnerList[i]!.Equals(other.InnerList[i]))
                         {
                             return false;
                         }
@@ -123,7 +125,8 @@ namespace System.Drawing
 
             public override int GetHashCode() => base.GetHashCode();
 
-            private WeakRefObject CreateWeakRefObject(object value)
+            [return: NotNullIfNotNull("value")]
+            private WeakRefObject? CreateWeakRefObject(object? value)
             {
                 if (value == null)
                 {
@@ -173,7 +176,7 @@ namespace System.Drawing
 
                 for (int idx = 0; idx < InnerList.Count; idx++)
                 {
-                    if (InnerList[idx] != null && InnerList[idx].GetHashCode() == hash)
+                    if (InnerList[idx] != null && InnerList[idx]!.GetHashCode() == hash)
                     {
                         RemoveAt(idx);
                         return;
@@ -185,17 +188,17 @@ namespace System.Drawing
 
             public bool IsFixedSize => InnerList.IsFixedSize;
 
-            public bool Contains(object value) => InnerList.Contains(CreateWeakRefObject(value));
+            public bool Contains(object? value) => InnerList.Contains(CreateWeakRefObject(value));
 
             public void RemoveAt(int index) => InnerList.RemoveAt(index);
 
-            public void Remove(object value) => InnerList.Remove(CreateWeakRefObject(value));
+            public void Remove(object? value) => InnerList.Remove(CreateWeakRefObject(value));
 
-            public int IndexOf(object value) => InnerList.IndexOf(CreateWeakRefObject(value));
+            public int IndexOf(object? value) => InnerList.IndexOf(CreateWeakRefObject(value));
 
-            public void Insert(int index, object value) => InnerList.Insert(index, CreateWeakRefObject(value));
+            public void Insert(int index, object? value) => InnerList.Insert(index, CreateWeakRefObject(value));
 
-            public int Add(object value)
+            public int Add(object? value)
             {
                 if (Count > RefCheckThreshold)
                 {
@@ -238,13 +241,13 @@ namespace System.Drawing
 
                 internal bool IsAlive => _weakHolder.IsAlive;
 
-                internal object Target => _weakHolder.Target;
+                internal object? Target => _weakHolder.Target;
 
                 public override int GetHashCode() => _hash;
 
-                public override bool Equals(object obj)
+                public override bool Equals(object? obj)
                 {
-                    WeakRefObject other = obj as WeakRefObject;
+                    WeakRefObject? other = obj as WeakRefObject;
 
                     if (other == this)
                     {
index c956ace..d44b474 100644 (file)
@@ -26,7 +26,7 @@ namespace System.Drawing.Design
         /// <summary>
         /// Represents the entry at the specified index of the <see cref='string'/>.
         /// </summary>
-        public string this[int index] => ((string)(InnerList[index]));
+        public string this[int index] => ((string)(InnerList[index])!);
 
         /// <summary>
         /// Gets a value indicating whether the  <see cref='CategoryNameCollection'/> contains the specified
index 4521f1a..1eff8d0 100644 (file)
@@ -14,18 +14,18 @@ namespace System.Drawing.Drawing2D
 #endif
 
         // Handle to native line cap object
-        internal SafeCustomLineCapHandle nativeCap = null;
+        internal SafeCustomLineCapHandle nativeCap = null!;
 
         private bool _disposed = false;
 
         // For subclass creation
         internal CustomLineCap() { }
 
-        public CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath) : this(fillPath, strokePath, LineCap.Flat) { }
+        public CustomLineCap(GraphicsPath? fillPath, GraphicsPath? strokePath) : this(fillPath, strokePath, LineCap.Flat) { }
 
-        public CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap) : this(fillPath, strokePath, baseCap, 0) { }
+        public CustomLineCap(GraphicsPath? fillPath, GraphicsPath? strokePath, LineCap baseCap) : this(fillPath, strokePath, baseCap, 0) { }
 
-        public CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap, float baseInset)
+        public CustomLineCap(GraphicsPath? fillPath, GraphicsPath? strokePath, LineCap baseCap, float baseInset)
         {
             IntPtr nativeLineCap;
             int status = Gdip.GdipCreateCustomLineCap(
index 5ece42d..5234e8d 100644 (file)
@@ -623,7 +623,7 @@ namespace System.Drawing.Drawing2D
             Gdip.CheckStatus(status);
         }
 
-        public void AddString(string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
+        public void AddString(string s, FontFamily family, int style, float emSize, Point origin, StringFormat? format)
         {
             Rectangle layout = default;
             layout.X = origin.X;
@@ -631,7 +631,7 @@ namespace System.Drawing.Drawing2D
             AddString(s, family, style, emSize, layout, format);
         }
 
-        public void AddString(string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
+        public void AddString(string s, FontFamily family, int style, float emSize, PointF origin, StringFormat? format)
         {
             RectangleF layout = default;
             layout.X = origin.X;
@@ -639,7 +639,7 @@ namespace System.Drawing.Drawing2D
             AddString(s, family, style, emSize, layout, format);
         }
 
-        public void AddString(string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
+        public void AddString(string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat? format)
         {
             if (family == null)
                 throw new ArgumentException(nameof(family));
@@ -650,7 +650,7 @@ namespace System.Drawing.Drawing2D
             Gdip.CheckStatus(status);
         }
 
-        public void AddString(string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
+        public void AddString(string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat? format)
         {
             if (family == null)
                 throw new ArgumentException(nameof(family));
@@ -692,7 +692,7 @@ namespace System.Drawing.Drawing2D
             Flatten(matrix, FlatnessDefault);
         }
 
-        public void Flatten(Matrix matrix, float flatness)
+        public void Flatten(Matrix? matrix, float flatness)
         {
             IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.NativeMatrix;
             int status = Gdip.GdipFlattenPath(_nativePath, m, flatness);
@@ -705,12 +705,12 @@ namespace System.Drawing.Drawing2D
             return GetBounds(null, null);
         }
 
-        public RectangleF GetBounds(Matrix matrix)
+        public RectangleF GetBounds(Matrix? matrix)
         {
             return GetBounds(matrix, null);
         }
 
-        public RectangleF GetBounds(Matrix matrix, Pen pen)
+        public RectangleF GetBounds(Matrix? matrix, Pen? pen)
         {
             RectangleF retval;
             IntPtr m = (matrix == null) ? IntPtr.Zero : matrix.NativeMatrix;
@@ -743,17 +743,17 @@ namespace System.Drawing.Drawing2D
             return IsOutlineVisible(x, y, pen, null);
         }
 
-        public bool IsOutlineVisible(Point pt, Pen pen, Graphics graphics)
+        public bool IsOutlineVisible(Point pt, Pen pen, Graphics? graphics)
         {
             return IsOutlineVisible(pt.X, pt.Y, pen, graphics);
         }
 
-        public bool IsOutlineVisible(PointF pt, Pen pen, Graphics graphics)
+        public bool IsOutlineVisible(PointF pt, Pen pen, Graphics? graphics)
         {
             return IsOutlineVisible(pt.X, pt.Y, pen, graphics);
         }
 
-        public bool IsOutlineVisible(int x, int y, Pen pen, Graphics graphics)
+        public bool IsOutlineVisible(int x, int y, Pen pen, Graphics? graphics)
         {
             if (pen == null)
                 throw new ArgumentNullException(nameof(pen));
@@ -767,7 +767,7 @@ namespace System.Drawing.Drawing2D
             return result;
         }
 
-        public bool IsOutlineVisible(float x, float y, Pen pen, Graphics graphics)
+        public bool IsOutlineVisible(float x, float y, Pen pen, Graphics? graphics)
         {
             if (pen == null)
                 throw new ArgumentNullException(nameof(pen));
@@ -801,17 +801,17 @@ namespace System.Drawing.Drawing2D
             return IsVisible(x, y, null);
         }
 
-        public bool IsVisible(Point pt, Graphics graphics)
+        public bool IsVisible(Point pt, Graphics? graphics)
         {
             return IsVisible(pt.X, pt.Y, graphics);
         }
 
-        public bool IsVisible(PointF pt, Graphics graphics)
+        public bool IsVisible(PointF pt, Graphics? graphics)
         {
             return IsVisible(pt.X, pt.Y, graphics);
         }
 
-        public bool IsVisible(int x, int y, Graphics graphics)
+        public bool IsVisible(int x, int y, Graphics? graphics)
         {
             bool retval;
 
@@ -824,7 +824,7 @@ namespace System.Drawing.Drawing2D
             return retval;
         }
 
-        public bool IsVisible(float x, float y, Graphics graphics)
+        public bool IsVisible(float x, float y, Graphics? graphics)
         {
             bool retval;
 
@@ -856,17 +856,17 @@ namespace System.Drawing.Drawing2D
             Warp(destPoints, srcRect, null, WarpMode.Perspective, FlatnessDefault);
         }
 
-        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix matrix)
+        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix? matrix)
         {
             Warp(destPoints, srcRect, matrix, WarpMode.Perspective, FlatnessDefault);
         }
 
-        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode)
+        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix? matrix, WarpMode warpMode)
         {
             Warp(destPoints, srcRect, matrix, warpMode, FlatnessDefault);
         }
 
-        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode, float flatness)
+        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix? matrix, WarpMode warpMode, float flatness)
         {
             if (destPoints == null)
                 throw new ArgumentNullException(nameof(destPoints));
@@ -884,12 +884,12 @@ namespace System.Drawing.Drawing2D
             Widen(pen, null, FlatnessDefault);
         }
 
-        public void Widen(Pen pen, Matrix matrix)
+        public void Widen(Pen pen, Matrix? matrix)
         {
             Widen(pen, matrix, FlatnessDefault);
         }
 
-        public void Widen(Pen pen, Matrix matrix, float flatness)
+        public void Widen(Pen pen, Matrix? matrix, float flatness)
         {
             if (pen == null)
                 throw new ArgumentNullException(nameof(pen));
index c895a84..249b397 100644 (file)
@@ -208,9 +208,9 @@ namespace System.Drawing.Drawing2D
 
         public bool IsVisible(PointF point) => IsVisible(point, null);
 
-        public bool IsVisible(float x, float y, Graphics graphics) => IsVisible(new PointF(x, y), graphics);
+        public bool IsVisible(float x, float y, Graphics? graphics) => IsVisible(new PointF(x, y), graphics);
 
-        public bool IsVisible(PointF pt, Graphics graphics)
+        public bool IsVisible(PointF pt, Graphics? graphics)
         {
             Gdip.CheckStatus(Gdip.GdipIsVisiblePathPoint(
                 new HandleRef(this, _nativePath),
@@ -225,9 +225,9 @@ namespace System.Drawing.Drawing2D
 
         public bool IsVisible(Point point) => IsVisible(point, null);
 
-        public bool IsVisible(int x, int y, Graphics graphics) => IsVisible(new Point(x, y), graphics);
+        public bool IsVisible(int x, int y, Graphics? graphics) => IsVisible(new Point(x, y), graphics);
 
-        public bool IsVisible(Point pt, Graphics graphics)
+        public bool IsVisible(Point pt, Graphics? graphics)
         {
             Gdip.CheckStatus(Gdip.GdipIsVisiblePathPointI(
                 new HandleRef(this, _nativePath),
@@ -242,12 +242,12 @@ namespace System.Drawing.Drawing2D
 
         public bool IsOutlineVisible(PointF point, Pen pen) => IsOutlineVisible(point, pen, null);
 
-        public bool IsOutlineVisible(float x, float y, Pen pen, Graphics graphics)
+        public bool IsOutlineVisible(float x, float y, Pen pen, Graphics? graphics)
         {
             return IsOutlineVisible(new PointF(x, y), pen, graphics);
         }
 
-        public bool IsOutlineVisible(PointF pt, Pen pen, Graphics graphics)
+        public bool IsOutlineVisible(PointF pt, Pen pen, Graphics? graphics)
         {
             if (pen == null)
                 throw new ArgumentNullException(nameof(pen));
@@ -266,9 +266,9 @@ namespace System.Drawing.Drawing2D
 
         public bool IsOutlineVisible(Point point, Pen pen) => IsOutlineVisible(point, pen, null);
 
-        public bool IsOutlineVisible(int x, int y, Pen pen, Graphics graphics) => IsOutlineVisible(new Point(x, y), pen, graphics);
+        public bool IsOutlineVisible(int x, int y, Pen pen, Graphics? graphics) => IsOutlineVisible(new Point(x, y), pen, graphics);
 
-        public bool IsOutlineVisible(Point pt, Pen pen, Graphics graphics)
+        public bool IsOutlineVisible(Point pt, Pen pen, Graphics? graphics)
         {
             if (pen == null)
                 throw new ArgumentNullException(nameof(pen));
@@ -627,17 +627,17 @@ namespace System.Drawing.Drawing2D
                 new HandleRef(this, _nativePath), new HandleRef(addingPath, addingPath._nativePath), connect));
         }
 
-        public void AddString(string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
+        public void AddString(string s, FontFamily family, int style, float emSize, PointF origin, StringFormat? format)
         {
             AddString(s, family, style, emSize, new RectangleF(origin.X, origin.Y, 0, 0), format);
         }
 
-        public void AddString(string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
+        public void AddString(string s, FontFamily family, int style, float emSize, Point origin, StringFormat? format)
         {
             AddString(s, family, style, emSize, new Rectangle(origin.X, origin.Y, 0, 0), format);
         }
 
-        public void AddString(string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
+        public void AddString(string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat? format)
         {
             Gdip.CheckStatus(Gdip.GdipAddPathString(
                 new HandleRef(this, _nativePath),
@@ -650,7 +650,7 @@ namespace System.Drawing.Drawing2D
                 new HandleRef(format, format?.nativeFormat ?? IntPtr.Zero)));
         }
 
-        public void AddString(string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
+        public void AddString(string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat? format)
         {
             Gdip.CheckStatus(Gdip.GdipAddPathStringI(
                 new HandleRef(this, _nativePath),
@@ -677,9 +677,9 @@ namespace System.Drawing.Drawing2D
 
         public RectangleF GetBounds() => GetBounds(null);
 
-        public RectangleF GetBounds(Matrix matrix) => GetBounds(matrix, null);
+        public RectangleF GetBounds(Matrix? matrix) => GetBounds(matrix, null);
 
-        public RectangleF GetBounds(Matrix matrix, Pen pen)
+        public RectangleF GetBounds(Matrix? matrix, Pen? pen)
         {
             Gdip.CheckStatus(Gdip.GdipGetPathWorldBounds(
                 new HandleRef(this, _nativePath),
@@ -692,9 +692,9 @@ namespace System.Drawing.Drawing2D
 
         public void Flatten() => Flatten(null);
 
-        public void Flatten(Matrix matrix) => Flatten(matrix, 0.25f);
+        public void Flatten(Matrix? matrix) => Flatten(matrix, 0.25f);
 
-        public void Flatten(Matrix matrix, float flatness)
+        public void Flatten(Matrix? matrix, float flatness)
         {
             Gdip.CheckStatus(Gdip.GdipFlattenPath(
                 new HandleRef(this, _nativePath),
@@ -704,9 +704,9 @@ namespace System.Drawing.Drawing2D
 
         public void Widen(Pen pen) => Widen(pen, null, Flatness);
 
-        public void Widen(Pen pen, Matrix matrix) => Widen(pen, matrix, Flatness);
+        public void Widen(Pen pen, Matrix? matrix) => Widen(pen, matrix, Flatness);
 
-        public void Widen(Pen pen, Matrix matrix, float flatness)
+        public void Widen(Pen pen, Matrix? matrix, float flatness)
         {
             if (pen == null)
                 throw new ArgumentNullException(nameof(pen));
@@ -725,14 +725,14 @@ namespace System.Drawing.Drawing2D
 
         public void Warp(PointF[] destPoints, RectangleF srcRect) => Warp(destPoints, srcRect, null);
 
-        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix matrix) => Warp(destPoints, srcRect, matrix, WarpMode.Perspective);
+        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix? matrix) => Warp(destPoints, srcRect, matrix, WarpMode.Perspective);
 
-        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode)
+        public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix? matrix, WarpMode warpMode)
         {
             Warp(destPoints, srcRect, matrix, warpMode, 0.25f);
         }
 
-        public unsafe void Warp(PointF[] destPoints, RectangleF srcRect, Matrix matrix, WarpMode warpMode, float flatness)
+        public unsafe void Warp(PointF[] destPoints, RectangleF srcRect, Matrix? matrix, WarpMode warpMode, float flatness)
         {
             if (destPoints == null)
                 throw new ArgumentNullException(nameof(destPoints));
index 769f0b6..b242775 100644 (file)
@@ -11,7 +11,7 @@ namespace System.Drawing.Drawing2D
 {
     public sealed class GraphicsPathIterator : MarshalByRefObject, IDisposable
     {
-        public GraphicsPathIterator(GraphicsPath path)
+        public GraphicsPathIterator(GraphicsPath? path)
         {
             IntPtr nativeIter = IntPtr.Zero;
             int status = Gdip.GdipCreatePathIter(out nativeIter, new HandleRef(path, (path == null) ? IntPtr.Zero : path._nativePath));
index 65c6afa..19228b5 100644 (file)
@@ -173,7 +173,7 @@ namespace System.Drawing.Drawing2D
             }
         }
 
-        public Blend Blend
+        public Blend? Blend
         {
             get
             {
index 0fe9a42..927de09 100644 (file)
@@ -263,10 +263,9 @@ namespace System.Drawing.Drawing2D
                 return isIdentity != 0;
             }
         }
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
-            Matrix matrix2 = obj as Matrix;
-            if (matrix2 == null)
+            if (!(obj is Matrix matrix2))
                 return false;
 
             Gdip.CheckStatus(Gdip.GdipIsMatrixEqual(
index 187e801..599aa73 100644 (file)
@@ -8,8 +8,8 @@ namespace System.Drawing.Drawing2D
     {
         public PathData() { }
 
-        public PointF[] Points { get; set; }
+        public PointF[]? Points { get; set; }
 
-        public byte[] Types { get; set; }
+        public byte[]? Types { get; set; }
     }
 }
index 687676b..bfa0659 100644 (file)
@@ -4,6 +4,7 @@
 
 using System.ComponentModel;
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 using System.Drawing.Internal;
 using System.Runtime.InteropServices;
 using Gdip = System.Drawing.SafeNativeMethods.Gdip;
@@ -361,7 +362,8 @@ namespace System.Drawing
             GC.SuppressFinalize(_fontFamily);
         }
 
-        private static string StripVerticalName(string familyName)
+        [return: NotNullIfNotNull("familyName")]
+        private static string? StripVerticalName(string? familyName)
         {
             if (familyName?.Length > 1 && familyName[0] == '@')
             {
index 6231cfe..b030638 100644 (file)
@@ -24,12 +24,12 @@ namespace System.Drawing
         private IntPtr _nativeFont;
         private float _fontSize;
         private FontStyle _fontStyle;
-        private FontFamily _fontFamily;
+        private FontFamily _fontFamily = null!;
         private GraphicsUnit _fontUnit;
         private byte _gdiCharSet = SafeNativeMethods.DEFAULT_CHARSET;
         private bool _gdiVerticalFont;
         private string _systemFontName = "";
-        private string _originalFontName;
+        private string _originalFontName = null!;
 
         // Return value is in Unit (the unit the font was created in)
         /// <summary>
@@ -140,9 +140,9 @@ namespace System.Drawing
 
         private Font(SerializationInfo info, StreamingContext context)
         {
-            string name = info.GetString("Name"); // Do not rename (binary serialization)
-            FontStyle style = (FontStyle)info.GetValue("Style", typeof(FontStyle)); // Do not rename (binary serialization)
-            GraphicsUnit unit = (GraphicsUnit)info.GetValue("Unit", typeof(GraphicsUnit)); // Do not rename (binary serialization)
+            string name = info.GetString("Name")!; // Do not rename (binary serialization)
+            FontStyle style = (FontStyle)info.GetValue("Style", typeof(FontStyle))!; // Do not rename (binary serialization)
+            GraphicsUnit unit = (GraphicsUnit)info.GetValue("Unit", typeof(GraphicsUnit))!; // Do not rename (binary serialization)
             float size = info.GetSingle("Size"); // Do not rename (binary serialization)
 
             Initialize(name, size, style, unit, SafeNativeMethods.DEFAULT_CHARSET, IsVerticalName(name));
@@ -221,7 +221,7 @@ namespace System.Drawing
         /// Returns a value indicating whether the specified object is a <see cref='Font'/> equivalent to this
         /// <see cref='Font'/>.
         /// </summary>
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (obj == this)
             {
index 277da4c..cffb588 100644 (file)
@@ -9,7 +9,7 @@ namespace System.Drawing
     /// </summary>
     public sealed partial class FontFamily : MarshalByRefObject, IDisposable
     {
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (obj == this)
             {
index c1405f4..81b8ef3 100644 (file)
@@ -9,7 +9,7 @@ namespace System.Drawing
     /// </summary>
     public sealed partial class FontFamily : MarshalByRefObject, IDisposable
     {
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (obj == this)
             {
index dbaed72..b77f226 100644 (file)
@@ -63,11 +63,11 @@ namespace System.Drawing
         /// Initializes a new instance of the <see cref='FontFamily'/> class in the specified
         /// <see cref='FontCollection'/> and with the specified name.
         /// </summary>
-        public FontFamily(string name, FontCollection fontCollection) => CreateFontFamily(name, fontCollection);
+        public FontFamily(string name, FontCollection? fontCollection) => CreateFontFamily(name, fontCollection);
 
         // Creates the native font family object.
         // Note: GDI+ creates singleton font family objects (from the corresponding font file) and reference count them.
-        private void CreateFontFamily(string name, FontCollection fontCollection)
+        private void CreateFontFamily(string name, FontCollection? fontCollection)
         {
             IntPtr fontfamily = IntPtr.Zero;
             IntPtr nativeFontCollection = (fontCollection == null) ? IntPtr.Zero : fontCollection._nativeFontCollection;
@@ -189,7 +189,7 @@ namespace System.Drawing
             char* name = stackalloc char[32]; // LF_FACESIZE is 32
             int status = Gdip.GdipGetFamilyName(new HandleRef(this, NativeFamily), name, language);
             Gdip.CheckStatus(status);
-            return Marshal.PtrToStringUni((IntPtr)name);
+            return Marshal.PtrToStringUni((IntPtr)name)!;
         }
 
         /// <summary>
index 1cac0ec..6fee50f 100644 (file)
@@ -50,7 +50,7 @@ namespace System.Drawing
                 get
                 {
                     LocalDataStoreSlot slot = Thread.GetNamedDataSlot(ThreadDataSlotName);
-                    IDictionary threadData = (IDictionary)Thread.GetData(slot);
+                    IDictionary? threadData = (IDictionary?)Thread.GetData(slot);
                     if (threadData == null)
                     {
                         threadData = new Hashtable();
@@ -406,7 +406,7 @@ namespace System.Drawing
         public static extern int DocumentProperties(HandleRef hwnd, HandleRef hPrinter, string pDeviceName, IntPtr /*DEVMODE*/ pDevModeOutput, IntPtr /*DEVMODE*/ pDevModeInput, int fMode);
 
         [DllImport(ExternDll.Winspool, SetLastError = true, CharSet = CharSet.Auto)]
-        public static extern int EnumPrinters(int flags, string name, int level, IntPtr pPrinterEnum/*buffer*/,
+        public static extern int EnumPrinters(int flags, string? name, int level, IntPtr pPrinterEnum/*buffer*/,
                                               int cbBuf, out int pcbNeeded, out int pcReturned);
 
         [DllImport(ExternDll.Gdi32, SetLastError = true, CharSet = CharSet.Auto)]
@@ -486,9 +486,9 @@ namespace System.Drawing
         public class DOCINFO
         {
             public int cbSize = 20;
-            public string lpszDocName;
-            public string lpszOutput;
-            public string lpszDatatype;
+            public string? lpszDocName;
+            public string? lpszOutput;
+            public string? lpszDatatype;
             public int fwType;
         }
 
@@ -510,8 +510,8 @@ namespace System.Drawing
             public IntPtr lCustData;
             public IntPtr lpfnPrintHook;
             public IntPtr lpfnSetupHook;
-            public string lpPrintTemplateName;
-            public string lpSetupTemplateName;
+            public string? lpPrintTemplateName;
+            public string? lpSetupTemplateName;
             public IntPtr hPrintTemplate;
             public IntPtr hSetupTemplate;
         }
@@ -534,8 +534,8 @@ namespace System.Drawing
             public IntPtr lCustData;
             public IntPtr lpfnPrintHook;
             public IntPtr lpfnSetupHook;
-            public string lpPrintTemplateName;
-            public string lpSetupTemplateName;
+            public string? lpPrintTemplateName;
+            public string? lpSetupTemplateName;
             public IntPtr hPrintTemplate;
             public IntPtr hSetupTemplate;
         }
@@ -613,7 +613,7 @@ namespace System.Drawing
         public class DEVMODE
         {
             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
-            public string dmDeviceName;
+            public string? dmDeviceName;
             public short dmSpecVersion;
             public short dmDriverVersion;
             public short dmSize;
@@ -633,7 +633,7 @@ namespace System.Drawing
             public short dmTTOption;
             public short dmCollate;
             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
-            public string dmFormName;
+            public string? dmFormName;
             public short dmLogPixels;
             public int dmBitsPerPel;
             public int dmPelsWidth;
index e48425f..a0a4968 100644 (file)
@@ -400,13 +400,13 @@ namespace System.Drawing
             internal static extern int GdipRecordMetafileFromDelegate_linux(StreamGetHeaderDelegate getHeader,
                 StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
                 StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref RectangleF frameRect,
-                MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+                MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
             internal static extern int GdipRecordMetafileFromDelegateI_linux(StreamGetHeaderDelegate getHeader,
                 StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
                 StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref Rectangle frameRect,
-                MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+                MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipGetPostScriptGraphicsContext(
index e6054f2..136f380 100644 (file)
@@ -240,7 +240,7 @@ namespace System.Drawing
             internal static extern int GdipGetImageBounds(HandleRef image, out RectangleF gprectf, out GraphicsUnit unit);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipGetImageThumbnail(HandleRef image, int thumbWidth, int thumbHeight, out IntPtr thumbImage, Image.GetThumbnailImageAbort callback, IntPtr callbackdata);
+            internal static extern int GdipGetImageThumbnail(HandleRef image, int thumbWidth, int thumbHeight, out IntPtr thumbImage, Image.GetThumbnailImageAbort? callback, IntPtr callbackdata);
 
             [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipGetImagePalette(HandleRef image, IntPtr palette, int size);
@@ -363,13 +363,13 @@ namespace System.Drawing
             internal static extern int GdipCreateMetafileFromStream(Interop.Ole32.IStream stream, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileStream(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileStream(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileStream(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileStream(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileStreamI(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileStreamI(Interop.Ole32.IStream stream, IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipComment(HandleRef graphics, int sizeData, byte[] data);
index 83d1534..c11ed0e 100644 (file)
@@ -343,7 +343,7 @@ namespace System.Drawing
             internal static extern int GdipDisposeImageAttributes(HandleRef imageattr);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipSetImageAttributesColorMatrix(HandleRef imageattr, ColorAdjustType type, bool enableFlag, ColorMatrix colorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag flags);
+            internal static extern int GdipSetImageAttributesColorMatrix(HandleRef imageattr, ColorAdjustType type, bool enableFlag, ColorMatrix? colorMatrix, ColorMatrix? grayMatrix, ColorMatrixFlag flags);
 
             [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipSetImageAttributesThreshold(HandleRef imageattr, ColorAdjustType type, bool enableFlag, float threshold);
@@ -1142,22 +1142,22 @@ namespace System.Drawing
             internal static extern int GdipCreateMetafileFromFile(string file, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipRecordMetafile(IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafile(IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafile(IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafile(IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileI(IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileI(IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileFileName(string fileName, IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileFileName(string fileName, IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileFileName(string fileName, IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileFileName(string fileName, IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Unicode)]
-            internal static extern int GdipRecordMetafileFileNameI(string fileName, IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string description, out IntPtr metafile);
+            internal static extern int GdipRecordMetafileFileNameI(string fileName, IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
 
             [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipPlayMetafileRecord(HandleRef metafile, EmfPlusRecordType recordType, int flags, int dataSize, byte[] data);
@@ -1307,16 +1307,16 @@ namespace System.Drawing
             internal static extern int GdipDrawImagePointsI(HandleRef graphics, HandleRef image, Point* points, int count);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipDrawImageRectRectI(HandleRef graphics, HandleRef image, int dstx, int dsty, int dstwidth, int dstheight, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort callback, HandleRef callbackdata);
+            internal static extern int GdipDrawImageRectRectI(HandleRef graphics, HandleRef image, int dstx, int dsty, int dstwidth, int dstheight, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort? callback, HandleRef callbackdata);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipDrawImagePointsRect(HandleRef graphics, HandleRef image, PointF* points, int count, float srcx, float srcy, float srcwidth, float srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort callback, HandleRef callbackdata);
+            internal static extern int GdipDrawImagePointsRect(HandleRef graphics, HandleRef image, PointF* points, int count, float srcx, float srcy, float srcwidth, float srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort? callback, HandleRef callbackdata);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipDrawImageRectRect(HandleRef graphics, HandleRef image, float dstx, float dsty, float dstwidth, float dstheight, float srcx, float srcy, float srcwidth, float srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort callback, HandleRef callbackdata);
+            internal static extern int GdipDrawImageRectRect(HandleRef graphics, HandleRef image, float dstx, float dsty, float dstwidth, float dstheight, float srcx, float srcy, float srcwidth, float srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort? callback, HandleRef callbackdata);
 
             [DllImport(LibraryName, ExactSpelling = true)]
-            internal static extern int GdipDrawImagePointsRectI(HandleRef graphics, HandleRef image, Point* points, int count, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort callback, HandleRef callbackdata);
+            internal static extern int GdipDrawImagePointsRectI(HandleRef graphics, HandleRef image, Point* points, int count, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort? callback, HandleRef callbackdata);
 
             [DllImport(LibraryName, ExactSpelling = true)]
             internal static extern int GdipDrawImageRect(HandleRef graphics, HandleRef image, float x, float y, float width, float height);
index 45b7ffb..4ac4853 100644 (file)
@@ -45,7 +45,7 @@ namespace System.Drawing
 {
     public sealed partial class Graphics : MarshalByRefObject, IDisposable, IDeviceContext
     {
-        internal IMacContext maccontext;
+        internal IMacContext? maccontext;
         private bool disposed = false;
         private static float defDpiX = 0;
         private static float defDpiY = 0;
@@ -156,7 +156,7 @@ namespace System.Drawing
             /* Get XVisualInfo for this visual */
             visual.visualid = LibX11Functions.XVisualIDFromVisual(defvisual);
             vPtr = LibX11Functions.XGetVisualInfo(Gdip.Display, 0x1 /* VisualIDMask */, ref visual, ref nitems);
-            visual = (XVisualInfo)Marshal.PtrToStructure(vPtr, typeof(XVisualInfo));
+            visual = (XVisualInfo)Marshal.PtrToStructure(vPtr, typeof(XVisualInfo))!;
             image = LibX11Functions.XGetImage(Gdip.Display, window, sourceX, sourceY, blockRegionSize.Width,
                 blockRegionSize.Height, AllPlanes, 2 /* ZPixmap*/);
             if (image == IntPtr.Zero)
@@ -331,62 +331,62 @@ namespace System.Drawing
             Gdip.CheckStatus(status);
         }
 
-        public void EnumerateMetafile(Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, Point[] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, Point[] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, PointF[] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, PointF[] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, Point[] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, Point[] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, PointF[] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, PointF[] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
 
-        public void EnumerateMetafile(Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
+        public void EnumerateMetafile(Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes? imageAttr)
         {
             throw new NotImplementedException();
         }
@@ -431,7 +431,7 @@ namespace System.Drawing
         }
 
         [EditorBrowsable(EditorBrowsableState.Advanced)]
-        public static Graphics FromHdcInternal(IntPtr hdc)
+        public static Graphics? FromHdcInternal(IntPtr hdc)
         {
             Gdip.Display = hdc;
             return null;
index e4b1712..e1506f2 100644 (file)
@@ -38,19 +38,19 @@ namespace System.Drawing
         /// We don't keep a GraphicsContext for the current context since it is available at any time from GDI+ and
         /// we don't want to keep track of changes in it.
         /// </summary>
-        private GraphicsContext _previousContext;
+        private GraphicsContext? _previousContext;
 
         private static readonly object s_syncObject = new object();
 
         // Object reference used for printing; it could point to a PrintPreviewGraphics to obtain the VisibleClipBounds, or
         // a DeviceContext holding a printer DC.
-        private object _printingHelper;
+        private object? _printingHelper;
 
         // GDI+'s preferred HPALETTE.
         private static IntPtr s_halftonePalette;
 
         // pointer back to the Image backing a specific graphic object
-        private Image _backingImage;
+        private Image? _backingImage;
 
         /// <summary>
         /// Constructor to initialize this object from a native GDI+ Graphics pointer.
@@ -151,7 +151,7 @@ namespace System.Drawing
             while (_previousContext != null)
             {
                 // Dispose entire stack.
-                GraphicsContext context = _previousContext.Previous;
+                GraphicsContext? context = _previousContext.Previous;
                 _previousContext.Dispose();
                 _previousContext = context;
             }
@@ -201,7 +201,7 @@ namespace System.Drawing
         /// Represents an object used in connection with the printing API, it is used to hold a reference to a
         /// PrintPreviewGraphics (fake graphics) or a printer DeviceContext (and maybe more in the future).
         /// </summary>
-        internal object PrintingHelper
+        internal object? PrintingHelper
         {
             get => _printingHelper;
             set
@@ -435,7 +435,7 @@ namespace System.Drawing
             PointF destPoint,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             Gdip.CheckStatus(Gdip.GdipEnumerateMetafileDestPoint(
                 new HandleRef(this, NativeGraphics),
@@ -450,7 +450,7 @@ namespace System.Drawing
             Point destPoint,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             Gdip.CheckStatus(Gdip.GdipEnumerateMetafileDestPointI(
                 new HandleRef(this, NativeGraphics),
@@ -466,7 +466,7 @@ namespace System.Drawing
             RectangleF destRect,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             Gdip.CheckStatus(Gdip.GdipEnumerateMetafileDestRect(
                 new HandleRef(this, NativeGraphics),
@@ -482,7 +482,7 @@ namespace System.Drawing
             Rectangle destRect,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             Gdip.CheckStatus(Gdip.GdipEnumerateMetafileDestRectI(
                 new HandleRef(this, NativeGraphics),
@@ -498,7 +498,7 @@ namespace System.Drawing
             PointF[] destPoints,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             if (destPoints == null)
                 throw new ArgumentNullException(nameof(destPoints));
@@ -522,7 +522,7 @@ namespace System.Drawing
             Point[] destPoints,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             if (destPoints == null)
                 throw new ArgumentNullException(nameof(destPoints));
@@ -548,7 +548,7 @@ namespace System.Drawing
             GraphicsUnit unit,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             Gdip.CheckStatus(Gdip.GdipEnumerateMetafileSrcRectDestPoint(
                 new HandleRef(this, NativeGraphics),
@@ -568,7 +568,7 @@ namespace System.Drawing
             GraphicsUnit unit,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             Gdip.CheckStatus(Gdip.GdipEnumerateMetafileSrcRectDestPointI(
                 new HandleRef(this, NativeGraphics),
@@ -588,7 +588,7 @@ namespace System.Drawing
             GraphicsUnit unit,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             Gdip.CheckStatus(Gdip.GdipEnumerateMetafileSrcRectDestRect(
                 new HandleRef(this, NativeGraphics),
@@ -608,7 +608,7 @@ namespace System.Drawing
             GraphicsUnit unit,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             Gdip.CheckStatus(Gdip.GdipEnumerateMetafileSrcRectDestRectI(
                 new HandleRef(this, NativeGraphics),
@@ -628,7 +628,7 @@ namespace System.Drawing
             GraphicsUnit unit,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             if (destPoints == null)
                 throw new ArgumentNullException(nameof(destPoints));
@@ -656,7 +656,7 @@ namespace System.Drawing
             GraphicsUnit unit,
             EnumerateMetafileProc callback,
             IntPtr callbackData,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             if (destPoints == null)
                 throw new ArgumentNullException(nameof(destPoints));
@@ -703,7 +703,7 @@ namespace System.Drawing
                 currentOffset.Y = elements[5];
             }
 
-            GraphicsContext context = _previousContext;
+            GraphicsContext? context = _previousContext;
 
             while (context != null)
             {
@@ -734,7 +734,7 @@ namespace System.Drawing
                 {
                     context = context.Previous;
 
-                    if (context == null || !context.Next.IsCumulative)
+                    if (context == null || !context.Next!.IsCumulative)
                     {
                         break;
                     }
@@ -786,7 +786,7 @@ namespace System.Drawing
         private void PopContext(int currentContextState)
         {
             Debug.Assert(_previousContext != null, "Trying to restore a context when the stack is empty");
-            GraphicsContext context = _previousContext;
+            GraphicsContext? context = _previousContext;
 
             // Pop all contexts up the stack.
             while (context != null)
@@ -920,7 +920,7 @@ namespace System.Drawing
 
         // This is called from AppDomain.ProcessExit and AppDomain.DomainUnload.
         [PrePrepareMethod]
-        private static void OnDomainUnload(object sender, EventArgs e)
+        private static void OnDomainUnload(object? sender, EventArgs e)
         {
             if (s_halftonePalette != IntPtr.Zero)
             {
index dbd458a..e488090 100644 (file)
@@ -1400,32 +1400,32 @@ namespace System.Drawing
         /// <summary>
         /// Draws a string with the specified font.
         /// </summary>
-        public void DrawString(string s, Font font, Brush brush, float x, float y)
+        public void DrawString(string? s, Font font, Brush brush, float x, float y)
         {
             DrawString(s, font, brush, new RectangleF(x, y, 0, 0), null);
         }
 
-        public void DrawString(string s, Font font, Brush brush, PointF point)
+        public void DrawString(string? s, Font font, Brush brush, PointF point)
         {
             DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), null);
         }
 
-        public void DrawString(string s, Font font, Brush brush, float x, float y, StringFormat format)
+        public void DrawString(string? s, Font font, Brush brush, float x, float y, StringFormat? format)
         {
             DrawString(s, font, brush, new RectangleF(x, y, 0, 0), format);
         }
 
-        public void DrawString(string s, Font font, Brush brush, PointF point, StringFormat format)
+        public void DrawString(string? s, Font font, Brush brush, PointF point, StringFormat? format)
         {
             DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
         }
 
-        public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle)
+        public void DrawString(string? s, Font font, Brush brush, RectangleF layoutRectangle)
         {
             DrawString(s, font, brush, layoutRectangle, null);
         }
 
-        public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
+        public void DrawString(string? s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat? format)
         {
             if (brush == null)
                 throw new ArgumentNullException(nameof(brush));
@@ -1445,10 +1445,10 @@ namespace System.Drawing
         }
 
         public SizeF MeasureString(
-            string text,
+            string? text,
             Font font,
             SizeF layoutArea,
-            StringFormat stringFormat,
+            StringFormat? stringFormat,
             out int charactersFitted,
             out int linesFilled)
         {
@@ -1479,7 +1479,7 @@ namespace System.Drawing
             return boundingBox.Size;
         }
 
-        public SizeF MeasureString(string text, Font font, PointF origin, StringFormat stringFormat)
+        public SizeF MeasureString(string? text, Font font, PointF origin, StringFormat? stringFormat)
         {
             if (string.IsNullOrEmpty(text))
                 return SizeF.Empty;
@@ -1503,9 +1503,9 @@ namespace System.Drawing
             return boundingBox.Size;
         }
 
-        public SizeF MeasureString(string text, Font font, SizeF layoutArea) => MeasureString(text, font, layoutArea, null);
+        public SizeF MeasureString(string? text, Font font, SizeF layoutArea) => MeasureString(text, font, layoutArea, null);
 
-        public SizeF MeasureString(string text, Font font, SizeF layoutArea, StringFormat stringFormat)
+        public SizeF MeasureString(string? text, Font font, SizeF layoutArea, StringFormat? stringFormat)
         {
             if (string.IsNullOrEmpty(text))
                 return SizeF.Empty;
@@ -1529,22 +1529,22 @@ namespace System.Drawing
             return boundingBox.Size;
         }
 
-        public SizeF MeasureString(string text, Font font)
+        public SizeF MeasureString(string? text, Font font)
         {
             return MeasureString(text, font, new SizeF(0, 0));
         }
 
-        public SizeF MeasureString(string text, Font font, int width)
+        public SizeF MeasureString(string? text, Font font, int width)
         {
             return MeasureString(text, font, new SizeF(width, 999999));
         }
 
-        public SizeF MeasureString(string text, Font font, int width, StringFormat format)
+        public SizeF MeasureString(string? text, Font font, int width, StringFormat? format)
         {
             return MeasureString(text, font, new SizeF(width, 999999), format);
         }
 
-        public Region[] MeasureCharacterRanges(string text, Font font, RectangleF layoutRect, StringFormat stringFormat)
+        public Region[] MeasureCharacterRanges(string? text, Font font, RectangleF layoutRect, StringFormat? stringFormat)
         {
             if (string.IsNullOrEmpty(text))
                 return Array.Empty<Region>();
@@ -1844,7 +1844,7 @@ namespace System.Drawing
             }
         }
 
-        public void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr)
+        public void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes? imageAttr)
         {
             DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, null, 0);
         }
@@ -1854,8 +1854,8 @@ namespace System.Drawing
             PointF[] destPoints,
             RectangleF srcRect,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttr,
-            DrawImageAbort callback)
+            ImageAttributes? imageAttr,
+            DrawImageAbort? callback)
         {
             DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback, 0);
         }
@@ -1865,8 +1865,8 @@ namespace System.Drawing
             PointF[] destPoints,
             RectangleF srcRect,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttr,
-            DrawImageAbort callback,
+            ImageAttributes? imageAttr,
+            DrawImageAbort? callback,
             int callbackData)
         {
             if (destPoints == null)
@@ -1905,7 +1905,7 @@ namespace System.Drawing
             Point[] destPoints,
             Rectangle srcRect,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, null, 0);
         }
@@ -1915,8 +1915,8 @@ namespace System.Drawing
             Point[] destPoints,
             Rectangle srcRect,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttr,
-            DrawImageAbort callback)
+            ImageAttributes? imageAttr,
+            DrawImageAbort? callback)
         {
             DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback, 0);
         }
@@ -1926,8 +1926,8 @@ namespace System.Drawing
             Point[] destPoints,
             Rectangle srcRect,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttr,
-            DrawImageAbort callback,
+            ImageAttributes? imageAttr,
+            DrawImageAbort? callback,
             int callbackData)
         {
             if (destPoints == null)
@@ -1976,7 +1976,7 @@ namespace System.Drawing
             float srcWidth,
             float srcHeight,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttrs)
+            ImageAttributes? imageAttrs)
         {
             DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs, null);
         }
@@ -1989,8 +1989,8 @@ namespace System.Drawing
             float srcWidth,
             float srcHeight,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttrs,
-            DrawImageAbort callback)
+            ImageAttributes? imageAttrs,
+            DrawImageAbort? callback)
         {
             DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs, callback, IntPtr.Zero);
         }
@@ -2003,8 +2003,8 @@ namespace System.Drawing
             float srcWidth,
             float srcHeight,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttrs,
-            DrawImageAbort callback,
+            ImageAttributes? imageAttrs,
+            DrawImageAbort? callback,
             IntPtr callbackData)
         {
             if (image == null)
@@ -2044,7 +2044,7 @@ namespace System.Drawing
             int srcWidth,
             int srcHeight,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttr)
+            ImageAttributes? imageAttr)
         {
             DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr, null);
         }
@@ -2057,8 +2057,8 @@ namespace System.Drawing
             int srcWidth,
             int srcHeight,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttr,
-            DrawImageAbort callback)
+            ImageAttributes? imageAttr,
+            DrawImageAbort? callback)
         {
             DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr, callback, IntPtr.Zero);
         }
@@ -2071,8 +2071,8 @@ namespace System.Drawing
             int srcWidth,
             int srcHeight,
             GraphicsUnit srcUnit,
-            ImageAttributes imageAttrs,
-            DrawImageAbort callback,
+            ImageAttributes? imageAttrs,
+            DrawImageAbort? callback,
             IntPtr callbackData)
         {
             if (image == null)
index fff41d1..eb4aeb8 100644 (file)
@@ -24,17 +24,17 @@ namespace System.Drawing
         /// <summary>
         /// The context's clip region.
         /// </summary>
-        private Region _clipRegion;
+        private Region? _clipRegion;
 
         /// <summary>
         /// The next context up the stack.
         /// </summary>
-        private GraphicsContext _nextContext;
+        private GraphicsContext? _nextContext;
 
         /// <summary>
         /// The previous context down the stack.
         /// </summary>
-        private GraphicsContext _prevContext;
+        private GraphicsContext? _prevContext;
 
         /// <summary>
         /// Flags that determines whether the context was created for a Graphics.Save() operation.
@@ -45,10 +45,6 @@ namespace System.Drawing
         /// </summary>
         private bool _isCumulative;
 
-        private GraphicsContext()
-        {
-        }
-
         public GraphicsContext(Graphics g)
         {
             Matrix transform = g.Transform;
@@ -128,7 +124,7 @@ namespace System.Drawing
         /// <summary>
         ///     The clipping region the GraphicsContext.
         /// </summary>
-        public Region Clip
+        public Region? Clip
         {
             get
             {
@@ -139,7 +135,7 @@ namespace System.Drawing
         /// <summary>
         /// The next GraphicsContext object in the stack.
         /// </summary>
-        public GraphicsContext Next
+        public GraphicsContext? Next
         {
             get
             {
@@ -154,7 +150,7 @@ namespace System.Drawing
         /// <summary>
         /// The previous GraphicsContext object in the stack.
         /// </summary>
-        public GraphicsContext Previous
+        public GraphicsContext? Previous
         {
             get
             {
index 2bf5642..62e345e 100644 (file)
@@ -103,25 +103,25 @@ namespace System.Drawing
         internal class IconImage : ImageData
         {
             internal BitmapInfoHeader iconHeader;   //image header
-            internal uint[] iconColors; //colors table
-            internal byte[] iconXOR;    // bits for XOR mask
-            internal byte[] iconAND;    //bits for AND mask
+            internal uint[]? iconColors; //colors table
+            internal byte[]? iconXOR;    // bits for XOR mask
+            internal byte[]? iconAND;    //bits for AND mask
         };
 
         [StructLayout(LayoutKind.Sequential)]
         internal class IconDump : ImageData
         {
-            internal byte[] data;
+            internal byte[]? data;
         };
 
         private Size iconSize;
         private IntPtr handle = IntPtr.Zero;
         private IconDir iconDir;
         private ushort id;
-        private ImageData[] imageData;
+        private ImageData[]? imageData;
         private bool undisposable;
         private bool disposed;
-        private Bitmap bitmap;
+        private Bitmap? bitmap;
 
         private Icon()
         {
@@ -246,7 +246,7 @@ namespace System.Drawing
             if (type == null)
                 throw new NullReferenceException();
 
-            using (Stream s = type.GetTypeInfo().Assembly.GetManifestResourceStream(type, resource))
+            using (Stream? s = type.GetTypeInfo().Assembly.GetManifestResourceStream(type, resource))
             {
                 if (s == null)
                 {
@@ -258,7 +258,7 @@ namespace System.Drawing
 
         internal Icon(string resourceName, bool undisposable)
         {
-            using (Stream s = typeof(Icon).GetTypeInfo().Assembly.GetManifestResourceStream(resourceName))
+            using (Stream? s = typeof(Icon).GetTypeInfo().Assembly.GetManifestResourceStream(resourceName))
             {
                 if (s == null)
                 {
@@ -293,8 +293,8 @@ namespace System.Drawing
 
         private Icon(SerializationInfo info, StreamingContext context)
         {
-            byte[] iconData = (byte[])info.GetValue("IconData", typeof(byte[])); // Do not rename (binary serialization)
-            Size iconSize = (Size)info.GetValue("IconSize", typeof(Size)); // Do not rename (binary serialization)
+            byte[] iconData = (byte[])info.GetValue("IconData", typeof(byte[]))!; // Do not rename (binary serialization)
+            Size iconSize = (Size)info.GetValue("IconSize", typeof(Size))!; // Do not rename (binary serialization)
             var dataStream = new MemoryStream(iconData);
 
             InitFromStreamWithSize(dataStream, iconSize.Width, iconSize.Height);
@@ -367,20 +367,20 @@ namespace System.Drawing
             writer.Write(bih.biClrImportant);
 
             //now write color table
-            int colCount = ii.iconColors.Length;
+            int colCount = ii.iconColors!.Length;
             for (int j = 0; j < colCount; j++)
                 writer.Write(ii.iconColors[j]);
 
             //now write XOR Mask
-            writer.Write(ii.iconXOR);
+            writer.Write(ii.iconXOR!);
 
             //now write AND Mask
-            writer.Write(ii.iconAND);
+            writer.Write(ii.iconAND!);
         }
 
         private void SaveIconDump(BinaryWriter writer, IconDump id)
         {
-            writer.Write(id.data);
+            writer.Write(id.data!);
         }
 
         private void SaveIconDirEntry(BinaryWriter writer, IconDirEntry ide, uint offset)
@@ -415,7 +415,7 @@ namespace System.Drawing
                 while (writer.BaseStream.Length < iconDir.idEntries[i].imageOffset)
                     writer.Write((byte)0);
 
-                if (imageData[i] is IconDump)
+                if (imageData![i] is IconDump)
                     SaveIconDump(writer, (IconDump)imageData[i]);
                 else
                     SaveIconImage(writer, (IconImage)imageData[i]);
@@ -446,7 +446,7 @@ namespace System.Drawing
             }
 
             SaveIconDirEntry(writer, iconDir.idEntries[best], 22);
-            SaveIconImage(writer, (IconImage)imageData[best]);
+            SaveIconImage(writer, (IconImage)imageData![best]);
         }
 
         private void SaveBitmapAsIcon(BinaryWriter writer)
@@ -457,7 +457,7 @@ namespace System.Drawing
 
             // when transformed into a bitmap only a single image exists
             IconDirEntry ide = default;
-            ide.width = (byte)bitmap.Width;
+            ide.width = (byte)bitmap!.Width;
             ide.height = (byte)bitmap.Height;
             ide.colorCount = 0; // 32 bbp == 0, for palette size
             ide.reserved = 0;   // always 0
@@ -574,7 +574,7 @@ namespace System.Drawing
             {
                 ColorPalette pal = bmp.Palette; // Managed palette
 
-                for (int i = 0; i < ii.iconColors.Length; i++)
+                for (int i = 0; i < ii.iconColors!.Length; i++)
                 {
                     pal.Entries[i] = Color.FromArgb((int)ii.iconColors[i] | unchecked((int)0xff000000));
                 }
@@ -586,7 +586,7 @@ namespace System.Drawing
 
             for (int y = 0; y < biHeight; y++)
             {
-                Marshal.Copy(ii.iconXOR, bytesPerLine * y,
+                Marshal.Copy(ii.iconXOR!, bytesPerLine * y,
                     (IntPtr)(bits.Scan0.ToInt64() + bits.Stride * (biHeight - 1 - y)), bytesPerLine);
             }
 
@@ -602,7 +602,7 @@ namespace System.Drawing
                 {
                     for (int bit = 7; bit >= 0; bit--)
                     {
-                        if (((ii.iconAND[y * bytesPerLine + x] >> bit) & 1) != 0)
+                        if (((ii.iconAND![y * bytesPerLine + x] >> bit) & 1) != 0)
                         {
                             bmp.SetPixel(x * 8 + 7 - bit, biHeight - y - 1, Color.Transparent);
                         }
index 5d5c054..ad69997 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Drawing
         private const int PNGSignature2 = 13 + (10 << 8) + (26 << 16) + (10 << 24);
 
         // Icon data
-        private readonly byte[] _iconData;
+        private readonly byte[]? _iconData;
         private uint _bestImageOffset;
         private uint _bestBitDepth;
         private uint _bestBytesInRes;
@@ -104,7 +104,7 @@ namespace System.Drawing
 
         public Icon(Type type, string resource) : this()
         {
-            Stream stream = type.Module.Assembly.GetManifestResourceStream(type, resource);
+            Stream? stream = type.Module.Assembly.GetManifestResourceStream(type, resource);
             if (stream == null)
             {
                 throw new ArgumentException(SR.Format(SR.ResourceNotFound, type, resource));
@@ -137,8 +137,8 @@ namespace System.Drawing
 
         private Icon(SerializationInfo info, StreamingContext context)
         {
-            _iconData = (byte[])info.GetValue("IconData", typeof(byte[])); // Do not rename (binary serialization)
-            _iconSize = (Size)info.GetValue("IconSize", typeof(Size)); // Do not rename (binary serialization)
+            _iconData = (byte[])info.GetValue("IconData", typeof(byte[]))!; // Do not rename (binary serialization)
+            _iconSize = (Size)info.GetValue("IconSize", typeof(Size))!; // Do not rename (binary serialization)
             Initialize(_iconSize.Width, _iconSize.Height);
         }
 
@@ -158,9 +158,9 @@ namespace System.Drawing
             si.AddValue("IconSize", _iconSize, typeof(Size)); // Do not rename (binary serialization)
         }
 
-        public static Icon ExtractAssociatedIcon(string filePath) => ExtractAssociatedIcon(filePath, 0);
+        public static Icon? ExtractAssociatedIcon(string filePath) => ExtractAssociatedIcon(filePath, 0);
 
-        private static unsafe Icon ExtractAssociatedIcon(string filePath, int index)
+        private static unsafe Icon? ExtractAssociatedIcon(string filePath, int index)
         {
             if (filePath == null)
             {
@@ -720,7 +720,7 @@ namespace System.Drawing
 
         private unsafe Bitmap BmpFrame()
         {
-            Bitmap bitmap = null;
+            Bitmap? bitmap = null;
             if (_iconData != null && _bestBitDepth == 32)
             {
                 // GDI+ doesnt handle 32 bpp icons with alpha properly
@@ -770,9 +770,9 @@ namespace System.Drawing
                         SafeNativeMethods.GetObject(new HandleRef(null, info.hbmColor), sizeof(SafeNativeMethods.BITMAP), ref bmp);
                         if (bmp.bmBitsPixel == 32)
                         {
-                            Bitmap tmpBitmap = null;
-                            BitmapData bmpData = null;
-                            BitmapData targetData = null;
+                            Bitmap? tmpBitmap = null;
+                            BitmapData? bmpData = null;
+                            BitmapData? targetData = null;
                             try
                             {
                                 tmpBitmap = Image.FromHbitmap(info.hbmColor);
@@ -833,7 +833,7 @@ namespace System.Drawing
 
                 Size size = Size;
                 bitmap = new Bitmap(size.Width, size.Height); // initialized to transparent
-                Graphics graphics = null;
+                Graphics? graphics = null;
                 using (graphics = Graphics.FromImage(bitmap))
                 {
                     try
index 21b6146..63bda67 100644 (file)
@@ -116,7 +116,7 @@ namespace System.Drawing
                 status = Gdip.GdipGetPropertyItem(nativeImage, propid, propSize, property);
                 Gdip.CheckStatus(status);
                 gdipProperty = (GdipPropertyItem)Marshal.PtrToStructure(property,
-                                    typeof(GdipPropertyItem));
+                                    typeof(GdipPropertyItem))!;
                 GdipPropertyItem.MarshalTo(gdipProperty, item);
             }
             finally
@@ -126,7 +126,7 @@ namespace System.Drawing
             return item;
         }
 
-        public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort callback, IntPtr callbackData)
+        public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort? callback, IntPtr callbackData)
         {
             if ((thumbWidth <= 0) || (thumbHeight <= 0))
                 throw new OutOfMemoryException(SR.InvalidThumbnailSize);
@@ -150,10 +150,10 @@ namespace System.Drawing
             return ThumbNail;
         }
 
-        internal ImageCodecInfo FindEncoderForFormat(ImageFormat format)
+        internal ImageCodecInfo? FindEncoderForFormat(ImageFormat format)
         {
             ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
-            ImageCodecInfo encoder = null;
+            ImageCodecInfo? encoder = null;
 
             if (format.Guid.Equals(ImageFormat.MemoryBmp.Guid))
                 format = ImageFormat.Png;
@@ -173,7 +173,7 @@ namespace System.Drawing
 
         public void Save(string filename, ImageFormat format)
         {
-            ImageCodecInfo encoder = FindEncoderForFormat(format);
+            ImageCodecInfo? encoder = FindEncoderForFormat(format);
             if (encoder == null)
             {
                 // second chance
@@ -187,7 +187,7 @@ namespace System.Drawing
             Save(filename, encoder, null);
         }
 
-        public void Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
+        public void Save(string filename, ImageCodecInfo encoder, EncoderParameters? encoderParams)
         {
             int st;
             Guid guid = encoder.Clsid;
@@ -214,14 +214,14 @@ namespace System.Drawing
                 dest = ImageFormat.Png;
 
             // If we don't find an Encoder (for things like Icon), we just switch back to PNG...
-            ImageCodecInfo codec = FindEncoderForFormat(dest) ?? FindEncoderForFormat(ImageFormat.Png);
+            ImageCodecInfo codec = FindEncoderForFormat(dest) ?? FindEncoderForFormat(ImageFormat.Png)!;
 
             Save(stream, codec, null);
         }
 
         public void Save(Stream stream, ImageFormat format)
         {
-            ImageCodecInfo encoder = FindEncoderForFormat(format);
+            ImageCodecInfo? encoder = FindEncoderForFormat(format);
 
             if (encoder == null)
                 throw new ArgumentException(SR.Format(SR.NoCodecAvailableForFormat, format.Guid));
@@ -229,7 +229,7 @@ namespace System.Drawing
             Save(stream, encoder, null);
         }
 
-        public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
+        public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters? encoderParams)
         {
             int st;
             IntPtr nativeEncoderParams;
@@ -284,7 +284,7 @@ namespace System.Drawing
             if (propitem == null)
                 throw new ArgumentNullException(nameof(propitem));
 
-            int nItemSize = Marshal.SizeOf(propitem.Value[0]);
+            int nItemSize = Marshal.SizeOf(propitem.Value![0]);
             int size = nItemSize * propitem.Value.Length;
             IntPtr dest = Marshal.AllocHGlobal(size);
             try
@@ -422,7 +422,7 @@ namespace System.Drawing
                     for (int i = 0; i < propNums; i++, propPtr = new IntPtr(propPtr.ToInt64() + propSize))
                     {
                         gdipProperty = (GdipPropertyItem)Marshal.PtrToStructure
-                            (propPtr, typeof(GdipPropertyItem));
+                            (propPtr, typeof(GdipPropertyItem))!;
                         items[i] = new PropertyItem();
                         GdipPropertyItem.MarshalTo(gdipProperty, items[i]);
                     }
index b504a7d..9732e24 100644 (file)
@@ -117,10 +117,10 @@ namespace System.Drawing
             if (format == null)
                 throw new ArgumentNullException(nameof(format));
 
-            ImageCodecInfo codec = format.FindEncoder();
+            ImageCodecInfo? codec = format.FindEncoder();
 
             if (codec == null)
-                codec = ImageFormat.Png.FindEncoder();
+                codec = ImageFormat.Png.FindEncoder()!;
 
             Save(filename, codec, null);
         }
@@ -128,7 +128,7 @@ namespace System.Drawing
         /// <summary>
         /// Saves this <see cref='Image'/> to the specified file in the specified format and with the specified encoder parameters.
         /// </summary>
-        public void Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
+        public void Save(string filename, ImageCodecInfo encoder, EncoderParameters? encoderParams)
         {
             if (filename == null)
                 throw new ArgumentNullException(nameof(filename));
@@ -150,7 +150,7 @@ namespace System.Drawing
 
                 if (_rawData != null)
                 {
-                    ImageCodecInfo rawEncoder = RawFormat.FindEncoder();
+                    ImageCodecInfo? rawEncoder = RawFormat.FindEncoder();
                     if (rawEncoder != null && rawEncoder.Clsid == g)
                     {
                         using (FileStream fs = File.OpenWrite(filename))
@@ -187,7 +187,7 @@ namespace System.Drawing
                 dest = ImageFormat.Png;
 
             // If we don't find an Encoder (for things like Icon), we just switch back to PNG...
-            ImageCodecInfo codec = dest.FindEncoder() ?? ImageFormat.Png.FindEncoder();
+            ImageCodecInfo codec = dest.FindEncoder() ?? ImageFormat.Png.FindEncoder()!;
 
             Save(stream, codec, null);
         }
@@ -200,14 +200,14 @@ namespace System.Drawing
             if (format == null)
                 throw new ArgumentNullException(nameof(format));
 
-            ImageCodecInfo codec = format.FindEncoder();
+            ImageCodecInfo codec = format.FindEncoder()!;
             Save(stream, codec, null);
         }
 
         /// <summary>
         /// Saves this <see cref='Image'/> to the specified stream in the specified format.
         /// </summary>
-        public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
+        public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters? encoderParams)
         {
             if (stream == null)
                 throw new ArgumentNullException(nameof(stream));
@@ -229,7 +229,7 @@ namespace System.Drawing
 
                 if (_rawData != null)
                 {
-                    ImageCodecInfo rawEncoder = RawFormat.FindEncoder();
+                    ImageCodecInfo? rawEncoder = RawFormat.FindEncoder();
                     if (rawEncoder != null && rawEncoder.Clsid == g)
                     {
                         stream.Write(_rawData, 0, _rawData.Length);
@@ -258,7 +258,7 @@ namespace System.Drawing
         /// <summary>
         /// Adds an <see cref='EncoderParameters'/> to this <see cref='Image'/>.
         /// </summary>
-        public void SaveAdd(EncoderParameters encoderParams)
+        public void SaveAdd(EncoderParameters? encoderParams)
         {
             IntPtr encoder = IntPtr.Zero;
             if (encoderParams != null)
@@ -282,7 +282,7 @@ namespace System.Drawing
         /// <summary>
         /// Adds an <see cref='EncoderParameters'/> to the specified <see cref='Image'/>.
         /// </summary>
-        public void SaveAdd(Image image, EncoderParameters encoderParams)
+        public void SaveAdd(Image image, EncoderParameters? encoderParams)
         {
             IntPtr encoder = IntPtr.Zero;
 
@@ -374,7 +374,7 @@ namespace System.Drawing
         /// <summary>
         /// Returns the thumbnail for this <see cref='Image'/>.
         /// </summary>
-        public Image GetThumbnailImage(int thumbWidth, int thumbHeight, GetThumbnailImageAbort callback, IntPtr callbackData)
+        public Image GetThumbnailImage(int thumbWidth, int thumbHeight, GetThumbnailImageAbort? callback, IntPtr callbackData)
         {
             IntPtr thumbImage = IntPtr.Zero;
 
@@ -414,7 +414,7 @@ namespace System.Drawing
         /// <summary>
         /// Gets the specified property item from this <see cref='Image'/>.
         /// </summary>
-        public PropertyItem GetPropertyItem(int propid)
+        public PropertyItem? GetPropertyItem(int propid)
         {
             Gdip.CheckStatus(Gdip.GdipGetPropertyItemSize(new HandleRef(this, nativeImage), propid, out int size));
 
index 37765ce..8adc665 100644 (file)
@@ -36,14 +36,14 @@ namespace System.Drawing
 
         internal IntPtr nativeImage;
 
-        private object _userData;
+        private object? _userData;
 
         // used to work around lack of animated gif encoder... rarely set...
-        private byte[] _rawData;
+        private byte[]? _rawData;
 
         [Localizable(false)]
         [DefaultValue(null)]
-        public object Tag
+        public object? Tag
         {
             get => _userData;
             set => _userData = value;
@@ -55,7 +55,7 @@ namespace System.Drawing
         private protected Image(SerializationInfo info, StreamingContext context)
 #pragma warning restore CA2229
         {
-            byte[] dat = (byte[])info.GetValue("Data", typeof(byte[])); // Do not rename (binary serialization)
+            byte[] dat = (byte[])info.GetValue("Data", typeof(byte[]))!; // Do not rename (binary serialization)
 
             try
             {
@@ -328,7 +328,7 @@ namespace System.Drawing
         /// <summary>
         /// Returns information about the codecs used for this <see cref='Image'/>.
         /// </summary>
-        public EncoderParameters GetEncoderParameterList(Guid encoder)
+        public EncoderParameters? GetEncoderParameterList(Guid encoder)
         {
             EncoderParameters p;
 
@@ -460,7 +460,7 @@ namespace System.Drawing
             }
         }
 
-        internal static unsafe void EnsureSave(Image image, string filename, Stream dataStream)
+        internal static unsafe void EnsureSave(Image image, string? filename, Stream? dataStream)
         {
             if (image.RawFormat.Equals(ImageFormat.Gif))
             {
@@ -495,7 +495,7 @@ namespace System.Drawing
                 {
                     try
                     {
-                        Stream created = null;
+                        Stream? created = null;
                         long lastPos = 0;
                         if (dataStream != null)
                         {
@@ -507,7 +507,7 @@ namespace System.Drawing
                         {
                             if (dataStream == null)
                             {
-                                created = dataStream = File.OpenRead(filename);
+                                created = dataStream = File.OpenRead(filename!);
                             }
 
                             image._rawData = new byte[(int)dataStream.Length];
@@ -521,7 +521,7 @@ namespace System.Drawing
                             }
                             else
                             {
-                                dataStream.Position = lastPos;
+                                dataStream!.Position = lastPos;
                             }
                         }
                     }
index 2cd76ed..8fa0c3f 100644 (file)
@@ -43,14 +43,14 @@ namespace System.Drawing
 
         private int frameCount;
         private int activeFrame;
-        private Thread thread;
+        private Thread? thread;
 
         public AnimateEventArgs(Image image)
         {
             frameCount = image.GetFrameCount(FrameDimension.Time);
         }
 
-        public Thread RunThread
+        public Thread? RunThread
         {
             get { return thread; }
             set { thread = value; }
@@ -87,7 +87,7 @@ namespace System.Drawing
                 return;
 
             PropertyItem item = image.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
-            byte[] value = item.Value;
+            byte[] value = item.Value!;
             int[] delay = new int[(value.Length >> 2)];
             for (int i = 0, n = 0; i < value.Length; i += 4, n++)
             {
@@ -105,7 +105,7 @@ namespace System.Drawing
             thread.Start();
         }
 
-        public static bool CanAnimate(Image image)
+        public static bool CanAnimate(Image? image)
         {
             if (image == null)
                 return false;
@@ -131,16 +131,16 @@ namespace System.Drawing
 
             if (ht.ContainsKey(image))
             {
-                AnimateEventArgs evtArgs = (AnimateEventArgs)ht[image];
-                evtArgs.RunThread.Abort();
+                AnimateEventArgs evtArgs = (AnimateEventArgs)ht[image]!;
+                evtArgs.RunThread!.Abort();
                 ht.Remove(image);
             }
         }
 
         public static void UpdateFrames()
         {
-            foreach (Image image in ht.Keys)
-                UpdateImageFrame(image);
+            foreach (Image? image in ht.Keys)
+                UpdateImageFrame(image!);
         }
 
 
@@ -156,7 +156,7 @@ namespace System.Drawing
         // this method avoid checks that aren't requied for UpdateFrames()
         private static void UpdateImageFrame(Image image)
         {
-            AnimateEventArgs aea = (AnimateEventArgs)ht[image];
+            AnimateEventArgs aea = (AnimateEventArgs)ht[image]!;
             image.SelectActiveFrame(FrameDimension.Time, aea.GetNextFrame());
         }
     }
index eae3070..fb5b72a 100644 (file)
@@ -37,7 +37,7 @@ namespace System.Drawing
         /// <summary>
         ///     A list of images to be animated.
         /// </summary>
-        private static List<ImageInfo> s_imageInfoList;
+        private static List<ImageInfo>? s_imageInfoList;
 
         /// <summary>
         ///     A variable to flag when an image or images need to be updated due to the selection of a new frame
@@ -50,7 +50,7 @@ namespace System.Drawing
         /// <summary>
         ///     The thread used for animating the images.
         /// </summary>
-        private static Thread s_animationThread;
+        private static Thread? s_animationThread;
 
         /// <summary>
         ///     Lock that allows either concurrent read-access to the images list for multiple threads, or write-
@@ -201,7 +201,7 @@ namespace System.Drawing
                 return;
             }
 
-            ImageInfo imageInfo = null;
+            ImageInfo? imageInfo = null;
 
             // See comment in the class header about locking the image ref.
 #pragma warning disable CA2002
@@ -285,7 +285,7 @@ namespace System.Drawing
         /// <summary>
         ///    Whether or not the image has multiple time-based frames.
         /// </summary>
-        public static bool CanAnimate(Image image)
+        public static bool CanAnimate(Image? image)
         {
             if (image == null)
             {
index ade085e..5579660 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Drawing
             private readonly int _frameCount;
             private bool _frameDirty;
             private readonly bool _animated;
-            private EventHandler _onFrameChangedHandler;
+            private EventHandler? _onFrameChangedHandler;
             private readonly int[] _frameDelay;
             private int _frameTimer;
 
@@ -33,12 +33,13 @@ namespace System.Drawing
             {
                 _image = image;
                 _animated = ImageAnimator.CanAnimate(image);
+                _frameDelay = null!; // guaranteed to be initialized by the final check
 
                 if (_animated)
                 {
                     _frameCount = image.GetFrameCount(FrameDimension.Time);
 
-                    PropertyItem frameDelayItem = image.GetPropertyItem(PropertyTagFrameDelay);
+                    PropertyItem? frameDelayItem = image.GetPropertyItem(PropertyTagFrameDelay);
 
                     // If the image does not have a frame delay, we just return 0.
                     //
@@ -46,7 +47,7 @@ namespace System.Drawing
                     {
                         // Convert the frame delay from byte[] to int
                         //
-                        byte[] values = frameDelayItem.Value;
+                        byte[] values = frameDelayItem.Value!;
                         Debug.Assert(values.Length == 4 * FrameCount, "PropertyItem has invalid value byte array");
                         _frameDelay = new int[FrameCount];
                         for (int i = 0; i < FrameCount; ++i)
@@ -116,7 +117,7 @@ namespace System.Drawing
                 }
             }
 
-            public EventHandler FrameChangedHandler
+            public EventHandler? FrameChangedHandler
             {
                 get
                 {
@@ -144,7 +145,7 @@ namespace System.Drawing
             /// </summary>
             public int FrameDelay(int frame)
             {
-                return _frameDelay[frame];
+                return _frameDelay![frame];
             }
 
             internal int FrameTimer
index a61c918..3256dc9 100644 (file)
@@ -95,7 +95,7 @@ namespace System.Drawing.Imaging
 
             for (int i = 0; i < count; i++)
             {
-                Guid guid = (Guid)Marshal.PtrToStructure((IntPtr)(i * size + arrayOffset), typeof(Guid));
+                Guid guid = (Guid)Marshal.PtrToStructure((IntPtr)(i * size + arrayOffset), typeof(Guid))!;
                 int numberOfValues = Marshal.ReadInt32((IntPtr)(i * size + arrayOffset + 16));
                 EncoderParameterValueType type = (EncoderParameterValueType)Marshal.ReadInt32((IntPtr)(i * size + arrayOffset + 20));
                 IntPtr value = Marshal.ReadIntPtr((IntPtr)(i * size + arrayOffset + 24));
@@ -115,7 +115,7 @@ namespace System.Drawing.Imaging
                     p.Dispose();
                 }
             }
-            _param = null;
+            _param = null!;
         }
     }
 }
index 09f8639..16c0739 100644 (file)
@@ -56,9 +56,9 @@ namespace System.Drawing.Imaging
         /// Returns a value indicating whether the specified object is an <see cref='FrameDimension'/> equivalent to
         /// this <see cref='FrameDimension'/>.
         /// </summary>
-        public override bool Equals(object o)
+        public override bool Equals(object? o)
         {
-            FrameDimension format = o as FrameDimension;
+            FrameDimension? format = o as FrameDimension;
             if (format == null)
                 return false;
             return _guid == format._guid;
index 2946f67..89af8dd 100644 (file)
@@ -200,17 +200,17 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Sets a color adjust matrix for image colors and a separate gray scale adjust matrix for gray scale values.
         /// </summary>
-        public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix)
+        public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix? grayMatrix)
         {
             SetColorMatrices(newColorMatrix, grayMatrix, ColorMatrixFlag.Default, ColorAdjustType.Default);
         }
 
-        public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag flags)
+        public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix? grayMatrix, ColorMatrixFlag flags)
         {
             SetColorMatrices(newColorMatrix, grayMatrix, flags, ColorAdjustType.Default);
         }
 
-        public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag mode,
+        public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix? grayMatrix, ColorMatrixFlag mode,
                                      ColorAdjustType type)
         {
             int status = Gdip.GdipSetImageAttributesColorMatrix(
index 977cb00..f51303f 100644 (file)
@@ -12,15 +12,15 @@ namespace System.Drawing.Imaging
     {
         private Guid _clsid;
         private Guid _formatID;
-        private string _codecName;
-        private string _dllName;
-        private string _formatDescription;
-        private string _filenameExtension;
-        private string _mimeType;
+        private string? _codecName;
+        private string? _dllName;
+        private string? _formatDescription;
+        private string? _filenameExtension;
+        private string? _mimeType;
         private ImageCodecFlags _flags;
         private int _version;
-        private byte[][] _signaturePatterns;
-        private byte[][] _signatureMasks;
+        private byte[][]? _signaturePatterns;
+        private byte[][]? _signatureMasks;
 
         internal ImageCodecInfo()
         {
@@ -38,13 +38,13 @@ namespace System.Drawing.Imaging
             set { _formatID = value; }
         }
 
-        public string CodecName
+        public string? CodecName
         {
             get { return _codecName; }
             set { _codecName = value; }
         }
 
-        public string DllName
+        public string? DllName
         {
             get
             {
@@ -56,19 +56,19 @@ namespace System.Drawing.Imaging
             }
         }
 
-        public string FormatDescription
+        public string? FormatDescription
         {
             get { return _formatDescription; }
             set { _formatDescription = value; }
         }
 
-        public string FilenameExtension
+        public string? FilenameExtension
         {
             get { return _filenameExtension; }
             set { _filenameExtension = value; }
         }
 
-        public string MimeType
+        public string? MimeType
         {
             get { return _mimeType; }
             set { _mimeType = value; }
@@ -87,14 +87,14 @@ namespace System.Drawing.Imaging
         }
 
         [CLSCompliant(false)]
-        public byte[][] SignaturePatterns
+        public byte[][]? SignaturePatterns
         {
             get { return _signaturePatterns; }
             set { _signaturePatterns = value; }
         }
 
         [CLSCompliant(false)]
-        public byte[][] SignatureMasks
+        public byte[][]? SignatureMasks
         {
             get { return _signatureMasks; }
             set { _signatureMasks = value; }
@@ -199,11 +199,11 @@ namespace System.Drawing.Imaging
 
                 for (int j = 0; j < codecp.SigCount; j++)
                 {
-                    codecs[index].SignaturePatterns[j] = new byte[codecp.SigSize];
-                    codecs[index].SignatureMasks[j] = new byte[codecp.SigSize];
+                    codecs[index].SignaturePatterns![j] = new byte[codecp.SigSize];
+                    codecs[index].SignatureMasks![j] = new byte[codecp.SigSize];
 
-                    Marshal.Copy((IntPtr)((long)codecp.SigMask + j * codecp.SigSize), codecs[index].SignatureMasks[j], 0, codecp.SigSize);
-                    Marshal.Copy((IntPtr)((long)codecp.SigPattern + j * codecp.SigSize), codecs[index].SignaturePatterns[j], 0, codecp.SigSize);
+                    Marshal.Copy((IntPtr)((long)codecp.SigMask + j * codecp.SigSize), codecs[index].SignatureMasks![j], 0, codecp.SigSize);
+                    Marshal.Copy((IntPtr)((long)codecp.SigPattern + j * codecp.SigSize), codecs[index].SignaturePatterns![j], 0, codecp.SigSize);
                 }
             }
 
index d025389..03bcb56 100644 (file)
@@ -129,9 +129,9 @@ namespace System.Drawing.Imaging
         /// Returns a value indicating whether the specified object is an <see cref='ImageFormat'/> equivalent to this
         /// <see cref='ImageFormat'/>.
         /// </summary>
-        public override bool Equals(object o)
+        public override bool Equals(object? o)
         {
-            ImageFormat format = o as ImageFormat;
+            ImageFormat? format = o as ImageFormat;
             if (format == null)
                 return false;
             return _guid == format._guid;
@@ -146,7 +146,7 @@ namespace System.Drawing.Imaging
         }
 
         // Find any random encoder which supports this format
-        internal ImageCodecInfo FindEncoder()
+        internal ImageCodecInfo? FindEncoder()
         {
             ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
             foreach (ImageCodecInfo codec in codecs)
index 2a6065e..d101b97 100644 (file)
@@ -70,23 +70,23 @@ namespace System.Drawing.Imaging
             Gdip.CheckStatus(status);
         }
 
-        public Metafile(IntPtr referenceHdc, EmfType emfType, string description) :
+        public Metafile(IntPtr referenceHdc, EmfType emfType, string? description) :
             this(referenceHdc, default(RectangleF), MetafileFrameUnit.GdiCompatible, emfType, description)
         {
         }
 
-        public Metafile(Stream stream, IntPtr referenceHdc, EmfType type, string description) :
+        public Metafile(Stream stream, IntPtr referenceHdc, EmfType type, string? description) :
             this(stream, referenceHdc, default(RectangleF), MetafileFrameUnit.GdiCompatible, type, description)
         {
         }
 
-        public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string description) :
+        public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string? description) :
             this(fileName, referenceHdc, default(RectangleF), MetafileFrameUnit.GdiCompatible, type, description)
         {
         }
 
         public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type,
-            string desc)
+            string? desc)
         {
             int status = Gdip.GdipRecordMetafileI(referenceHdc, type, ref frameRect, frameUnit,
                 desc, out nativeImage);
@@ -94,7 +94,7 @@ namespace System.Drawing.Imaging
         }
 
         public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit,
-            EmfType type, string description)
+            EmfType type, string? description)
         {
             if (stream == null)
                 throw new NullReferenceException(nameof(stream));
@@ -113,7 +113,7 @@ namespace System.Drawing.Imaging
         }
 
         public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit,
-            EmfType type, string description)
+            EmfType type, string? description)
         {
             if (stream == null)
                 throw new NullReferenceException(nameof(stream));
@@ -132,7 +132,7 @@ namespace System.Drawing.Imaging
         }
 
         public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit,
-            EmfType type, string description)
+            EmfType type, string? description)
         {
             // Called in order to emulate exception behavior from .NET Framework related to invalid file paths.
             Path.GetFullPath(fileName);
index f264f32..bf2f537 100644 (file)
@@ -42,7 +42,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class from the specified handle to a device context.
         /// </summary>
-        public Metafile(IntPtr referenceHdc, EmfType emfType, string description)
+        public Metafile(IntPtr referenceHdc, EmfType emfType, string? description)
         {
             Gdip.CheckStatus(Gdip.GdipRecordMetafile(
                 referenceHdc,
@@ -59,7 +59,7 @@ namespace System.Drawing.Imaging
         /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
         /// by the specified rectangle.
         /// </summary>
-        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string desc)
+        public Metafile(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string? desc)
         {
             IntPtr metafile = IntPtr.Zero;
 
@@ -90,7 +90,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string description)
+        public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string? description)
         {
             // Called in order to emulate exception behavior from .NET Framework related to invalid file paths.
             Path.GetFullPath(fileName);
@@ -110,7 +110,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
+        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string? description)
         {
             // Called in order to emulate exception behavior from .NET Framework related to invalid file paths.
             Path.GetFullPath(fileName);
@@ -146,7 +146,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class from the specified data stream.
         /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, EmfType type, string description)
+        public Metafile(Stream stream, IntPtr referenceHdc, EmfType type, string? description)
         {
             Gdip.CheckStatus(Gdip.GdipRecordMetafileStream(
                 new GPStream(stream),
@@ -163,7 +163,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
+        public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string? description)
         {
             Gdip.CheckStatus(Gdip.GdipRecordMetafileStream(
                 new GPStream(stream),
@@ -180,7 +180,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
-        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
+        public Metafile(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, string? description)
         {
             IntPtr metafile = IntPtr.Zero;
 
@@ -264,14 +264,14 @@ namespace System.Drawing.Imaging
                     metafileType == MetafileType.WmfPlaceable)
                 {
                     // WMF header
-                    header.wmf = (MetafileHeaderWmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderWmf));
+                    header.wmf = (MetafileHeaderWmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderWmf))!;
                     header.emf = null;
                 }
                 else
                 {
                     // EMF header
                     header.wmf = null;
-                    header.emf = (MetafileHeaderEmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderEmf));
+                    header.emf = (MetafileHeaderEmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderEmf))!;
                 }
             }
             finally
@@ -307,14 +307,14 @@ namespace System.Drawing.Imaging
                     metafileType == MetafileType.WmfPlaceable)
                 {
                     // WMF header
-                    header.wmf = (MetafileHeaderWmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderWmf));
+                    header.wmf = (MetafileHeaderWmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderWmf))!;
                     header.emf = null;
                 }
                 else
                 {
                     // EMF header
                     header.wmf = null;
-                    header.emf = (MetafileHeaderEmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderEmf));
+                    header.emf = (MetafileHeaderEmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderEmf))!;
                 }
             }
             finally
@@ -350,14 +350,14 @@ namespace System.Drawing.Imaging
                     metafileType == MetafileType.WmfPlaceable)
                 {
                     // WMF header
-                    header.wmf = (MetafileHeaderWmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderWmf));
+                    header.wmf = (MetafileHeaderWmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderWmf))!;
                     header.emf = null;
                 }
                 else
                 {
                     // EMF header
                     header.wmf = null;
-                    header.emf = (MetafileHeaderEmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderEmf));
+                    header.emf = (MetafileHeaderEmf)Marshal.PtrToStructure(memory, typeof(MetafileHeaderEmf))!;
                 }
             }
             finally
index 3c6291b..006659e 100644 (file)
@@ -100,7 +100,7 @@ namespace System.Drawing.Imaging
         /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded
         /// by the specified rectangle.
         /// </summary>
-        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
+        public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string? description)
         {
             Gdip.CheckStatus(Gdip.GdipRecordMetafile(
                 referenceHdc,
@@ -174,7 +174,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, string desc) :
+        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, string? desc) :
             this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, desc)
         {
         }
@@ -182,7 +182,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description)
+        public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string? description)
         {
             // Called in order to emulate exception behavior from .NET Framework related to invalid file paths.
             Path.GetFullPath(fileName);
@@ -230,7 +230,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
         /// </summary>
-        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, string description) :
+        public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, string? description) :
             this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, description)
         {
         }
index 2edfe77..2acbf32 100644 (file)
@@ -14,8 +14,8 @@ namespace System.Drawing.Imaging
     public sealed class MetafileHeader
     {
         // determine which to use by nullity
-        internal MetafileHeaderWmf wmf;
-        internal MetafileHeaderEmf emf;
+        internal MetafileHeaderWmf? wmf;
+        internal MetafileHeaderEmf? emf;
 
         internal MetafileHeader()
         {
@@ -28,7 +28,7 @@ namespace System.Drawing.Imaging
         {
             get
             {
-                return IsWmf() ? wmf.type : emf.type;
+                return IsWmf() ? wmf!.type : emf!.type;
             }
         }
 
@@ -39,7 +39,7 @@ namespace System.Drawing.Imaging
         {
             get
             {
-                return IsWmf() ? wmf.size : emf.size;
+                return IsWmf() ? wmf!.size : emf!.size;
             }
         }
 
@@ -50,7 +50,7 @@ namespace System.Drawing.Imaging
         {
             get
             {
-                return IsWmf() ? wmf.version : emf.version;
+                return IsWmf() ? wmf!.version : emf!.version;
             }
         }
 
@@ -61,7 +61,7 @@ namespace System.Drawing.Imaging
         {
             get
             {
-                return IsWmf() ? wmf.dpiX : emf.dpiX;
+                return IsWmf() ? wmf!.dpiX : emf!.dpiX;
             }
         }
 
@@ -72,7 +72,7 @@ namespace System.Drawing.Imaging
         {
             get
             {
-                return IsWmf() ? wmf.dpiY : emf.dpiY;
+                return IsWmf() ? wmf!.dpiY : emf!.dpiY;
             }
         }
 
@@ -84,8 +84,8 @@ namespace System.Drawing.Imaging
             get
             {
                 return IsWmf() ?
-                    new Rectangle(wmf.X, wmf.Y, wmf.Width, wmf.Height) :
-                    new Rectangle(emf.X, emf.Y, emf.Width, emf.Height);
+                    new Rectangle(wmf!.X, wmf.Y, wmf.Width, wmf.Height) :
+                    new Rectangle(emf!.X, emf.Y, emf.Width, emf.Height);
             }
         }
 
@@ -181,7 +181,7 @@ namespace System.Drawing.Imaging
         public bool IsDisplay()
         {
             return IsEmfPlus() &&
-               (((unchecked((int)emf.emfPlusFlags)) & ((int)EmfPlusFlags.Display)) != 0);
+               (((unchecked((int)emf!.emfPlusFlags)) & ((int)EmfPlusFlags.Display)) != 0);
         }
 
         /// <summary>
@@ -208,7 +208,7 @@ namespace System.Drawing.Imaging
                 if (wmf == null && emf == null)
                     throw Gdip.StatusException(Gdip.InvalidParameter);
 
-                return IsWmf() ? wmf.EmfPlusHeaderSize : emf.EmfPlusHeaderSize;
+                return IsWmf() ? wmf!.EmfPlusHeaderSize : emf!.EmfPlusHeaderSize;
             }
         }
 
@@ -222,7 +222,7 @@ namespace System.Drawing.Imaging
                 if (wmf == null && emf == null)
                     throw Gdip.StatusException(Gdip.InvalidParameter);
 
-                return IsWmf() ? wmf.LogicalDpiX : emf.LogicalDpiX;
+                return IsWmf() ? wmf!.LogicalDpiX : emf!.LogicalDpiX;
             }
         }
 
@@ -236,7 +236,7 @@ namespace System.Drawing.Imaging
                 if (wmf == null && emf == null)
                     throw Gdip.StatusException(Gdip.InvalidParameter);
 
-                return IsWmf() ? wmf.LogicalDpiY : emf.LogicalDpiX;
+                return IsWmf() ? wmf!.LogicalDpiY : emf!.LogicalDpiX;
             }
         }
     }
index b7d762a..8053f55 100644 (file)
@@ -23,7 +23,7 @@ namespace System.Drawing.Imaging
         public int Y;
         public int Width;
         public int Height;
-        public SafeNativeMethods.ENHMETAHEADER EmfHeader;
+        public SafeNativeMethods.ENHMETAHEADER? EmfHeader;
         public int EmfPlusHeaderSize;
         public int LogicalDpiX;
         public int LogicalDpiY;
index de3ebb4..7ee82f8 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Drawing.Imaging
         private int _id;
         private int _len;
         private short _type;
-        private byte[] _value;
+        private byte[]? _value;
 
         internal PropertyItem()
         {
@@ -46,7 +46,7 @@ namespace System.Drawing.Imaging
         /// <summary>
         /// Contains the property value.
         /// </summary>
-        public byte[] Value
+        public byte[]? Value
         {
             get { return _value; }
             set { _value = value; }
index 892bbde..5c339e7 100644 (file)
@@ -139,7 +139,7 @@ namespace System.Drawing.Internal
                 for (int i = 0; i < count; i++)
                 {
                     Debug.Assert(list[i] != null, "null value in active part of list");
-                    ISystemColorTracker tracker = (ISystemColorTracker)list[i].Target;
+                    ISystemColorTracker? tracker = (ISystemColorTracker?)list[i].Target;
                     if (tracker != null)
                     {
                         // If object still around
index e6307b5..2e05e77 100644 (file)
@@ -43,7 +43,7 @@ namespace System.Drawing
             int nPointSize = Marshal.SizeOf(pts[0]);
             IntPtr pos = prt;
             for (int i = 0; i < pts.Length; i++, pos = new IntPtr(pos.ToInt64() + nPointSize))
-                pts[i] = (Point)Marshal.PtrToStructure(pos, typeof(Point));
+                pts[i] = (Point)Marshal.PtrToStructure(pos, typeof(Point))!;
 
             Marshal.FreeHGlobal(prt);
         }
@@ -54,7 +54,7 @@ namespace System.Drawing
             int nPointSize = Marshal.SizeOf(pts[0]);
             IntPtr pos = prt;
             for (int i = 0; i < pts.Length; i++, pos = new IntPtr(pos.ToInt64() + nPointSize))
-                pts[i] = (PointF)Marshal.PtrToStructure(pos, typeof(PointF));
+                pts[i] = (PointF)Marshal.PtrToStructure(pos, typeof(PointF))!;
 
             Marshal.FreeHGlobal(prt);
         }
index 03ac8b4..669aab7 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Drawing
         // libgdiplus does not implement GdipGetPenCustomEndCap, so we cache the last-known value here.
         // Note that this value is not necessarily in sync with the true native value of this property,
         // as it could have been set outside of the CustomEndCap property on this type.
-        private CustomLineCap _cachedEndCap;
+        private CustomLineCap? _cachedEndCap;
 
         /// <summary>
         /// Gets or sets a custom cap style to use at the beginning of lines drawn with this <see cref='Pen'/>.
@@ -68,7 +68,7 @@ namespace System.Drawing
                 }
 
                 // Windows GDI+ clones the CustomLineCap before storing it in the Pen.
-                CustomLineCap clone = value == null ? null : (CustomLineCap)value.Clone();
+                CustomLineCap? clone = value == null ? null : (CustomLineCap)value.Clone();
 
                 int status = Gdip.GdipSetPenCustomEndCap(
                     new HandleRef(this, NativePen),
index 39253b5..c25fc83 100644 (file)
@@ -608,7 +608,7 @@ namespace System.Drawing
         {
             get
             {
-                Brush brush = null;
+                Brush? brush = null;
 
                 switch (PenType)
                 {
@@ -636,7 +636,7 @@ namespace System.Drawing
                         break;
                 }
 
-                return brush;
+                return brush!;
             }
             set
             {
index 27d2319..707d277 100644 (file)
@@ -313,7 +313,7 @@ namespace System.Drawing
 
         private static Pen GetPen(object key, Color color)
         {
-            Pen Pen = (Pen)Gdip.ThreadData[key];
+            Pen? Pen = (Pen?)Gdip.ThreadData[key];
             if (Pen == null)
             {
                 Pen = new Pen(color, true);
index 151fcb5..29c84ad 100644 (file)
@@ -14,8 +14,8 @@ namespace System.Drawing.Printing
     /// </summary>
     public class StandardPrintController : PrintController
     {
-        private DeviceContext _dc;
-        private Graphics _graphics;
+        private DeviceContext? _dc;
+        private Graphics? _graphics;
 
         /// <summary>
         /// Implements StartPrint for printing to a physical printer.
@@ -23,6 +23,7 @@ namespace System.Drawing.Printing
         public override void OnStartPrint(PrintDocument document, PrintEventArgs e)
         {
             Debug.Assert(_dc == null && _graphics == null, "PrintController methods called in the wrong order?");
+            Debug.Assert(_modeHandle != null);
 
             base.OnStartPrint(document, e);
             // the win32 methods below SuppressUnmanagedCodeAttributes so assertin on UnmanagedCodePermission is redundant
@@ -60,6 +61,7 @@ namespace System.Drawing.Printing
         public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e)
         {
             Debug.Assert(_dc != null && _graphics == null, "PrintController methods called in the wrong order?");
+            Debug.Assert(_modeHandle != null);
 
             base.OnStartPage(document, e);
             e.PageSettings.CopyToHdevmode(_modeHandle);
@@ -76,7 +78,7 @@ namespace System.Drawing.Printing
 
             _graphics = Graphics.FromHdcInternal(_dc.Hdc);
 
-            if (_graphics != null && document.OriginAtMargins)
+            if (document.OriginAtMargins)
             {
                 // Adjust the origin of the graphics object to be at the
                 // user-specified margin location
index 49b389b..0e3dbe6 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Drawing.Printing
     [Serializable]
     public partial class InvalidPrinterException : SystemException
     {
-        private readonly PrinterSettings _settings;
+        private readonly PrinterSettings? _settings;
 
         /// <summary>
         /// Initializes a new instance of the <see cref='InvalidPrinterException'/> class.
index a83af80..5d06d99 100644 (file)
@@ -194,7 +194,7 @@ namespace System.Drawing.Printing
         /// Compares this <see cref='Margins'/> to a specified <see cref='Margins'/> to see whether they
         /// are equal.
         /// </summary>
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (!(obj is Margins margins))
             {
@@ -215,7 +215,7 @@ namespace System.Drawing.Printing
         /// <summary>
         /// Tests whether two <see cref='Margins'/> objects are identical.
         /// </summary>
-        public static bool operator ==(Margins m1, Margins m2)
+        public static bool operator ==(Margins? m1, Margins? m2)
         {
             if (m1 is null)
             {
@@ -232,7 +232,7 @@ namespace System.Drawing.Printing
         /// <summary>
         /// Tests whether two <see cref='Margins'/> objects are different.
         /// </summary>
-        public static bool operator !=(Margins m1, Margins m2) => !(m1 == m2);
+        public static bool operator !=(Margins? m1, Margins? m2) => !(m1 == m2);
 
         /// <summary>
         /// Provides some interesting information for the Margins in String form.
index 4c35e8f..543628e 100644 (file)
@@ -54,7 +54,7 @@ namespace System.Drawing.Printing
         private float hardMarginX;
         private float hardMarginY;
         private RectangleF printableArea;
-        private PrinterSettings printerSettings;
+        private PrinterSettings printerSettings = null!;
 #pragma warning restore 649
 
         public PageSettings() : this(new PrinterSettings())
index 4279a50..1303dc5 100644 (file)
@@ -16,9 +16,9 @@ namespace System.Drawing.Printing
         internal PrinterSettings printerSettings;
 
         private TriState _color = TriState.Default;
-        private PaperSize _paperSize;
-        private PaperSource _paperSource;
-        private PrinterResolution _printerResolution;
+        private PaperSize? _paperSize;
+        private PaperSource? _paperSource;
+        private PrinterResolution? _printerResolution;
         private TriState _landscape = TriState.Default;
         private Margins _margins = new Margins();
 
@@ -164,7 +164,7 @@ namespace System.Drawing.Printing
                 {
                     IntPtr modeHandle = printerSettings.GetHdevmode();
                     IntPtr modePointer = Interop.Kernel32.GlobalLock(new HandleRef(this, modeHandle));
-                    SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE));
+                    SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE))!;
 
                     PaperSource result = PaperSourceFromMode(mode);
 
@@ -233,7 +233,7 @@ namespace System.Drawing.Printing
                 {
                     IntPtr modeHandle = printerSettings.GetHdevmode();
                     IntPtr modePointer = Interop.Kernel32.GlobalLock(new HandleRef(this, modeHandle));
-                    SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE));
+                    SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE))!;
 
                     PrinterResolution result = PrinterResolutionFromMode(mode);
 
@@ -281,7 +281,7 @@ namespace System.Drawing.Printing
         public void CopyToHdevmode(IntPtr hdevmode)
         {
             IntPtr modePointer = Interop.Kernel32.GlobalLock(hdevmode);
-            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE));
+            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE))!;
 
             if (_color.IsNotDefault && ((mode.dmFields & SafeNativeMethods.DM_COLOR) == SafeNativeMethods.DM_COLOR))
                 mode.dmColor = unchecked((short)(((bool)_color) ? SafeNativeMethods.DMCOLOR_COLOR : SafeNativeMethods.DMCOLOR_MONOCHROME));
@@ -382,7 +382,7 @@ namespace System.Drawing.Printing
             {
                 IntPtr modeHandle = printerSettings.GetHdevmodeInternal();
                 IntPtr modePointer = Interop.Kernel32.GlobalLock(new HandleRef(this, modeHandle));
-                SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE));
+                SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE))!;
 
                 short result = mode?.dmDriverExtra ?? 0;
 
@@ -427,7 +427,7 @@ namespace System.Drawing.Printing
                 }
 
                 IntPtr modePointer = Interop.Kernel32.GlobalLock(modeHandle);
-                SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE));
+                SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE))!;
 
                 PaperSize result = PaperSizeFromMode(mode);
 
@@ -515,7 +515,7 @@ namespace System.Drawing.Printing
             }
 
             IntPtr pointer = Interop.Kernel32.GlobalLock(hdevmode);
-            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));
+            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE))!;
 
             if ((mode.dmFields & SafeNativeMethods.DM_COLOR) == SafeNativeMethods.DM_COLOR)
             {
index db57f08..8fe2578 100644 (file)
@@ -47,9 +47,9 @@ namespace System.Drawing.Printing
                 throw new InvalidPrinterException(document.PrinterSettings);
             }
 
-            foreach (PreviewPageInfo pi in _list)
+            foreach (PreviewPageInfo? pi in _list)
             {
-                pi.Image.Dispose();
+                pi!.Image.Dispose();
             }
 
             _list.Clear();
index 6a99e82..e50fd61 100644 (file)
@@ -15,8 +15,8 @@ namespace System.Drawing.Printing
     /// </summary>
     public partial class PreviewPrintController : PrintController
     {
-        private Graphics _graphics;
-        private DeviceContext _dc;
+        private Graphics? _graphics;
+        private DeviceContext? _dc;
 
         /// <summary>
         /// Implements StartPrint for generating print preview information.
@@ -32,7 +32,7 @@ namespace System.Drawing.Printing
 
             // We need a DC as a reference; we don't actually draw on it.
             // We make sure to reuse the same one to improve performance.
-            _dc = document.PrinterSettings.CreateInformationContext(_modeHandle);
+            _dc = document.PrinterSettings.CreateInformationContext(_modeHandle!);
         }
 
         /// <summary>
@@ -44,7 +44,7 @@ namespace System.Drawing.Printing
 
             if (e.CopySettingsToDevMode)
             {
-                e.PageSettings.CopyToHdevmode(_modeHandle);
+                e.PageSettings.CopyToHdevmode(_modeHandle!);
             }
 
             Size size = e.PageBounds.Size;
@@ -62,14 +62,14 @@ namespace System.Drawing.Printing
             // is sufficiently large and has more than 254 colors.
             // This code path can easily be avoided by requesting
             // an EmfPlusOnly EMF..
-            Metafile metafile = new Metafile(_dc.Hdc, new Rectangle(0, 0, metafileSize.Width, metafileSize.Height), MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusOnly);
+            Metafile metafile = new Metafile(_dc!.Hdc, new Rectangle(0, 0, metafileSize.Width, metafileSize.Height), MetafileFrameUnit.GdiCompatible, EmfType.EmfPlusOnly);
 
             PreviewPageInfo info = new PreviewPageInfo(metafile, size);
             _list.Add(info);
             PrintPreviewGraphics printGraphics = new PrintPreviewGraphics(document, e);
             _graphics = Graphics.FromImage(metafile);
 
-            if (_graphics != null && document.OriginAtMargins)
+            if (document.OriginAtMargins)
             {
                 // Adjust the origin of the graphics object to be at the
                 // user-specified margin location
index 8dec0c4..e47770e 100644 (file)
@@ -65,7 +65,7 @@ namespace System.Drawing.Printing
             }
         }
 
-        private protected SafeDeviceModeHandle _modeHandle = null;
+        private protected SafeDeviceModeHandle? _modeHandle = null;
 
         /// <remarks>
         /// If you have nested PrintControllers, this method won't get called on the inner one.
@@ -145,7 +145,7 @@ namespace System.Drawing.Printing
                 }
 
                 PrintPageEventArgs pageEvent = CreatePrintPageEvent(queryEvent.PageSettings);
-                Graphics graphics = OnStartPage(document, pageEvent);
+                Graphics? graphics = OnStartPage(document, pageEvent);
                 pageEvent.SetGraphics(graphics);
 
                 try
@@ -171,7 +171,7 @@ namespace System.Drawing.Printing
 
         private bool PrintLoopOptimized(PrintDocument document)
         {
-            PrintPageEventArgs pageEvent = null;
+            PrintPageEventArgs? pageEvent = null;
             PageSettings documentPageSettings = (PageSettings)document.DefaultPageSettings.Clone();
             QueryPageSettingsEventArgs queryEvent = new QueryPageSettingsEventArgs(documentPageSettings);
             while (true)
@@ -198,14 +198,14 @@ namespace System.Drawing.Printing
                         pageEvent.CopySettingsToDevMode = false;
                     }
 
-                    Graphics graphics = OnStartPage(document, pageEvent);
+                    Graphics? graphics = OnStartPage(document, pageEvent);
                     pageEvent.SetGraphics(graphics);
                 }
                 else
                 {
                     // Page settings were customized, so use the customized ones in the start page event.
                     pageEvent = CreatePrintPageEvent(queryEvent.PageSettings);
-                    Graphics graphics = OnStartPage(document, pageEvent);
+                    Graphics? graphics = OnStartPage(document, pageEvent);
                     pageEvent.SetGraphics(graphics);
                 }
 
@@ -216,7 +216,7 @@ namespace System.Drawing.Printing
                 }
                 finally
                 {
-                    pageEvent.Graphics.Dispose();
+                    pageEvent.Graphics!.Dispose();
                     pageEvent.SetGraphics(null);
                 }
 
index c7b7d74..7ca9afa 100644 (file)
@@ -15,7 +15,7 @@ namespace System.Drawing.Printing
         /// <summary>
         /// When overridden in a derived class, begins the control sequence of when and how to print a page in a document.
         /// </summary>
-        public virtual Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e)
+        public virtual Graphics? OnStartPage(PrintDocument document, PrintPageEventArgs e)
         {
             return null;
         }
index 304d556..90f79eb 100644 (file)
@@ -142,7 +142,7 @@ namespace System.Drawing.Printing
             if (printArgs.Cancel)
                 return;
 
-            Graphics g = null;
+            Graphics? g = null;
 
             if (printArgs.GraphicsContext != null)
             {
@@ -155,7 +155,7 @@ namespace System.Drawing.Printing
             do
             {
                 QueryPageSettingsEventArgs queryPageSettingsArgs = new QueryPageSettingsEventArgs(
-                        DefaultPageSettings.Clone() as PageSettings);
+                        (DefaultPageSettings.Clone() as PageSettings)!);
                 OnQueryPageSettings(queryPageSettingsArgs);
 
                 PageSettings pageSettings = queryPageSettingsArgs.PageSettings;
@@ -169,7 +169,7 @@ namespace System.Drawing.Printing
                 // size, orientation, etc. We use a single graphic for now to keep Cairo using a single PDF file.
 
                 printPageArgs.GraphicsContext = printArgs.GraphicsContext;
-                Graphics pg = PrintController.OnStartPage(this, printPageArgs);
+                Graphics? pg = PrintController.OnStartPage(this, printPageArgs);
 
                 // assign Graphics in printPageArgs
                 printPageArgs.SetGraphics(pg);
@@ -221,15 +221,15 @@ namespace System.Drawing.Printing
         }
 
         [SRDescription("Raised when printing begins")]
-        public event PrintEventHandler BeginPrint;
+        public event PrintEventHandler? BeginPrint;
 
         [SRDescription("Raised when printing ends")]
-        public event PrintEventHandler EndPrint;
+        public event PrintEventHandler? EndPrint;
 
         [SRDescription("Raised when printing of a new page begins")]
-        public event PrintPageEventHandler PrintPage;
+        public event PrintPageEventHandler? PrintPage;
 
         [SRDescription("Raised before printing of a new page begins")]
-        public event QueryPageSettingsEventHandler QueryPageSettings;
+        public event QueryPageSettingsEventHandler? QueryPageSettings;
     }
 }
index ea844d5..47d0ef8 100644 (file)
@@ -14,15 +14,15 @@ namespace System.Drawing.Printing
     {
         private string _documentName = "document";
 
-        private PrintEventHandler _beginPrintHandler;
-        private PrintEventHandler _endPrintHandler;
-        private PrintPageEventHandler _printPageHandler;
-        private QueryPageSettingsEventHandler _queryHandler;
+        private PrintEventHandler? _beginPrintHandler;
+        private PrintEventHandler? _endPrintHandler;
+        private PrintPageEventHandler? _printPageHandler;
+        private QueryPageSettingsEventHandler? _queryHandler;
 
         private PrinterSettings _printerSettings = new PrinterSettings();
         private PageSettings _defaultPageSettings;
 
-        private PrintController _printController;
+        private PrintController? _printController;
 
         private bool _originAtMargins;
         private bool _userSetPageSettings;
index 24dcd4e..b31f08e 100644 (file)
@@ -40,7 +40,7 @@ namespace System.Drawing.Printing
     /// </summary>
     public class PrintEventArgs : System.ComponentModel.CancelEventArgs
     {
-        private GraphicsPrinter graphics_context;
+        private GraphicsPrinter? graphics_context;
         private PrintAction action;
 
         public PrintEventArgs()
@@ -57,7 +57,7 @@ namespace System.Drawing.Printing
             get { return action; }
         }
 
-        internal GraphicsPrinter GraphicsContext
+        internal GraphicsPrinter? GraphicsContext
         {
             get { return graphics_context; }
             set { graphics_context = value; }
index 866ea75..8316e93 100644 (file)
@@ -42,14 +42,14 @@ namespace System.Drawing.Printing
     public class PrintPageEventArgs : EventArgs
     {
         private bool cancel;
-        private Graphics graphics;
+        private Graphics? graphics;
         private bool hasmorePages;
         private Rectangle marginBounds;
         private Rectangle pageBounds;
         private PageSettings pageSettings;
-        private GraphicsPrinter graphics_context;
+        private GraphicsPrinter? graphics_context;
 
-        public PrintPageEventArgs(Graphics graphics, Rectangle marginBounds,
+        public PrintPageEventArgs(Graphics? graphics, Rectangle marginBounds,
             Rectangle pageBounds, PageSettings pageSettings)
         {
             this.graphics = graphics;
@@ -68,7 +68,7 @@ namespace System.Drawing.Printing
                 cancel = value;
             }
         }
-        public Graphics Graphics
+        public Graphics? Graphics
         {
             get
             {
@@ -109,12 +109,12 @@ namespace System.Drawing.Printing
         }
 
         // used in PrintDocument.Print()
-        internal void SetGraphics(Graphics g)
+        internal void SetGraphics(Graphics? g)
         {
             graphics = g;
         }
 
-        internal GraphicsPrinter GraphicsContext
+        internal GraphicsPrinter? GraphicsContext
         {
             get { return graphics_context; }
             set { graphics_context = value; }
index a51595d..1648840 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Drawing.Printing
         private bool _hasMorePages;
         private bool _cancel;
 
-        private Graphics _graphics;
+        private Graphics? _graphics;
         private readonly Rectangle _marginBounds;
         private readonly Rectangle _pageBounds;
         private readonly PageSettings _pageSettings;
@@ -25,7 +25,7 @@ namespace System.Drawing.Printing
         /// <summary>
         /// Initializes a new instance of the <see cref='PrintPageEventArgs'/> class.
         /// </summary>
-        public PrintPageEventArgs(Graphics graphics, Rectangle marginBounds, Rectangle pageBounds, PageSettings pageSettings)
+        public PrintPageEventArgs(Graphics? graphics, Rectangle marginBounds, Rectangle pageBounds, PageSettings pageSettings)
         {
             _graphics = graphics; // may be null, see PrintController
             _marginBounds = marginBounds;
@@ -45,7 +45,7 @@ namespace System.Drawing.Printing
         /// <summary>
         /// Gets the <see cref='System.Drawing.Graphics'/> used to paint the item.
         /// </summary>
-        public Graphics Graphics
+        public Graphics? Graphics
         {
             get
             {
@@ -100,10 +100,10 @@ namespace System.Drawing.Printing
         /// </summary>
         internal void Dispose()
         {
-            _graphics.Dispose();
+            _graphics!.Dispose();
         }
 
-        internal void SetGraphics(Graphics value)
+        internal void SetGraphics(Graphics? value)
         {
             _graphics = value;
         }
index 134261c..b5a2030 100644 (file)
@@ -43,7 +43,7 @@ namespace System.Drawing.Printing
     public class PrinterSettings : ICloneable
     {
         private string printer_name;
-        private string print_filename;
+        private string? print_filename;
         private short copies;
         private int maximum_page;
         private int minimum_page;
@@ -56,14 +56,14 @@ namespace System.Drawing.Printing
         internal bool supports_color;
         internal int landscape_angle;
         private bool print_tofile;
-        internal PrinterSettings.PrinterResolutionCollection printer_resolutions;
-        internal PrinterSettings.PaperSizeCollection paper_sizes;
-        internal PrinterSettings.PaperSourceCollection paper_sources;
-        private PageSettings default_pagesettings;
+        internal PrinterSettings.PrinterResolutionCollection? printer_resolutions;
+        internal PrinterSettings.PaperSizeCollection? paper_sizes;
+        internal PrinterSettings.PaperSourceCollection? paper_sources;
+        private PageSettings? default_pagesettings;
         private Duplex duplex;
         internal bool is_plotter;
 
-        internal NameValueCollection printer_capabilities; // this stores a list of all the printer options. Used only in cups, but might come in handy on win too.
+        internal NameValueCollection? printer_capabilities; // this stores a list of all the printer options. Used only in cups, but might come in handy on win too.
 
         public PrinterSettings()
         {
@@ -200,7 +200,7 @@ namespace System.Drawing.Printing
             }
         }
 
-        public PrinterSettings.PaperSizeCollection PaperSizes
+        public PrinterSettings.PaperSizeCollection? PaperSizes
         {
             get
             {
@@ -211,7 +211,7 @@ namespace System.Drawing.Printing
             }
         }
 
-        public PrinterSettings.PaperSourceCollection PaperSources
+        public PrinterSettings.PaperSourceCollection? PaperSources
         {
             get
             {
@@ -221,8 +221,7 @@ namespace System.Drawing.Printing
                 return paper_sources;
             }
         }
-        public
-        string PrintFileName
+        public string? PrintFileName
         {
             get { return print_filename; }
             set { print_filename = value; }
@@ -392,10 +391,10 @@ namespace System.Drawing.Printing
             bool ICollection.IsSynchronized { get { return false; } }
             object ICollection.SyncRoot { get { return this; } }
             [EditorBrowsable(EditorBrowsableState.Never)]
-            public int Add(PaperSource paperSource) { return _PaperSources.Add(paperSource); }
+            public int Add(PaperSource? paperSource) { return _PaperSources.Add(paperSource); }
             public void CopyTo(PaperSource[] paperSources, int index) { throw new NotImplementedException(); }
 
-            public virtual PaperSource this[int index]
+            public virtual PaperSource? this[int index]
             {
                 get { return _PaperSources[index] as PaperSource; }
             }
@@ -437,10 +436,10 @@ namespace System.Drawing.Printing
             bool ICollection.IsSynchronized { get { return false; } }
             object ICollection.SyncRoot { get { return this; } }
             [EditorBrowsable(EditorBrowsableState.Never)]
-            public int Add(PaperSize paperSize) { return _PaperSizes.Add(paperSize); }
+            public int Add(PaperSize? paperSize) { return _PaperSizes.Add(paperSize); }
             public void CopyTo(PaperSize[] paperSizes, int index) { throw new NotImplementedException(); }
 
-            public virtual PaperSize this[int index]
+            public virtual PaperSize? this[int index]
             {
                 get { return _PaperSizes[index] as PaperSize; }
             }
@@ -481,10 +480,10 @@ namespace System.Drawing.Printing
             bool ICollection.IsSynchronized { get { return false; } }
             object ICollection.SyncRoot { get { return this; } }
             [EditorBrowsable(EditorBrowsableState.Never)]
-            public int Add(PrinterResolution printerResolution) { return _PrinterResolutions.Add(printerResolution); }
+            public int Add(PrinterResolution? printerResolution) { return _PrinterResolutions.Add(printerResolution); }
             public void CopyTo(PrinterResolution[] printerResolutions, int index) { throw new NotImplementedException(); }
 
-            public virtual PrinterResolution this[int index]
+            public virtual PrinterResolution? this[int index]
             {
                 get { return _PrinterResolutions[index] as PrinterResolution; }
             }
@@ -527,7 +526,7 @@ namespace System.Drawing.Printing
 
             public virtual string this[int index]
             {
-                get { return _Strings[index] as string; }
+                get { return (_Strings[index] as string)!; }
             }
             [EditorBrowsable(EditorBrowsableState.Never)]
             public int Add(string value) { return _Strings.Add(value); }
index a123443..fce1dd4 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Drawing.Printing
         // Also, all properties have hidden tri-state logic -- yes/no/default
         private const int Padding64Bit = 4;
 
-        private string _printerName; // default printer.
+        private string? _printerName; // default printer.
         private string _driverName = "";
         private string _outputPort = "";
         private bool _printToFile;
@@ -34,7 +34,7 @@ namespace System.Drawing.Printing
         private bool _printDialogDisplayed;
 
         private short _extrabytes;
-        private byte[] _extrainfo;
+        private byte[]? _extrainfo;
 
         private short _copies = -1;
         private Duplex _duplex = System.Drawing.Printing.Duplex.Default;
@@ -47,7 +47,7 @@ namespace System.Drawing.Printing
         private PrintRange _printRange;
 
         private short _devmodebytes;
-        private byte[] _cachedDevmode;
+        private byte[]? _cachedDevmode;
 
         /// <summary>
         /// Initializes a new instance of the <see cref='PrinterSettings'/> class.
@@ -208,7 +208,7 @@ namespace System.Drawing.Printing
                     // The printer name is at offset 0
                     //
                     IntPtr namePointer = (IntPtr)Marshal.ReadIntPtr((IntPtr)(checked((long)buffer + i * sizeofstruct)));
-                    array[i] = Marshal.PtrToStringAuto(namePointer);
+                    array[i] = Marshal.PtrToStringAuto(namePointer)!;
                 }
 
                 Marshal.FreeCoTaskMem(buffer);
@@ -556,7 +556,7 @@ namespace System.Drawing.Printing
         internal DeviceContext CreateDeviceContext(PageSettings pageSettings)
         {
             IntPtr modeHandle = GetHdevmodeInternal();
-            DeviceContext dc = null;
+            DeviceContext? dc = null;
 
             try
             {
@@ -574,7 +574,7 @@ namespace System.Drawing.Printing
         internal DeviceContext CreateDeviceContext(IntPtr hdevmode)
         {
             IntPtr modePointer = Interop.Kernel32.GlobalLock(hdevmode);
-            DeviceContext dc = DeviceContext.CreateDC(DriverName, PrinterNameInternal, (string)null, modePointer);
+            DeviceContext dc = DeviceContext.CreateDC(DriverName, PrinterNameInternal, fileName:null, modePointer); ;
             Interop.Kernel32.GlobalUnlock(hdevmode);
             return dc;
         }
@@ -603,7 +603,7 @@ namespace System.Drawing.Printing
         internal DeviceContext CreateInformationContext(IntPtr hdevmode)
         {
             IntPtr modePointer = Interop.Kernel32.GlobalLock(hdevmode);
-            DeviceContext dc = DeviceContext.CreateIC(DriverName, PrinterNameInternal, (string)null, modePointer);
+            DeviceContext dc = DeviceContext.CreateIC(DriverName, PrinterNameInternal, fileName:null, modePointer);
             Interop.Kernel32.GlobalUnlock(hdevmode);
             return dc;
         }
@@ -617,7 +617,7 @@ namespace System.Drawing.Printing
         public Graphics CreateMeasurementGraphics(bool honorOriginAtMargins)
         {
             Graphics g = CreateMeasurementGraphics();
-            if (g != null && honorOriginAtMargins)
+            if (honorOriginAtMargins)
             {
                 g.TranslateTransform(-_defaultPageSettings.HardMarginX, -_defaultPageSettings.HardMarginY);
                 g.TranslateTransform(_defaultPageSettings.Margins.Left, _defaultPageSettings.Margins.Top);
@@ -638,7 +638,7 @@ namespace System.Drawing.Printing
         public Graphics CreateMeasurementGraphics(PageSettings pageSettings, bool honorOriginAtMargins)
         {
             Graphics g = CreateMeasurementGraphics();
-            if (g != null && honorOriginAtMargins)
+            if (honorOriginAtMargins)
             {
                 g.TranslateTransform(-pageSettings.HardMarginX, -pageSettings.HardMarginY);
                 g.TranslateTransform(pageSettings.Margins.Left, pageSettings.Margins.Top);
@@ -883,7 +883,7 @@ namespace System.Drawing.Printing
                 }
             }
 
-            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));
+            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE))!;
 
 
             if (_extrainfo != null)
@@ -1003,7 +1003,7 @@ namespace System.Drawing.Printing
                 }
 
                 IntPtr modePointer = Interop.Kernel32.GlobalLock(new HandleRef(this, modeHandle));
-                SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE));
+                SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE))!;
                 switch (field)
                 {
                     case ModeField.Orientation:
@@ -1083,7 +1083,7 @@ namespace System.Drawing.Printing
             PaperSize[] result = new PaperSize[count];
             for (int i = 0; i < count; i++)
             {
-                string name = Marshal.PtrToStringAuto((IntPtr)(checked((long)namesBuffer + stringSize * i)), 64);
+                string name = Marshal.PtrToStringAuto((IntPtr)(checked((long)namesBuffer + stringSize * i)), 64)!;
                 int index = name.IndexOf('\0');
                 if (index > -1)
                 {
@@ -1125,7 +1125,7 @@ namespace System.Drawing.Printing
             PaperSource[] result = new PaperSource[count];
             for (int i = 0; i < count; i++)
             {
-                string name = Marshal.PtrToStringAuto((IntPtr)(checked((long)namesBuffer + stringSize * i)), 24);
+                string name = Marshal.PtrToStringAuto((IntPtr)(checked((long)namesBuffer + stringSize * i)), 24)!;
                 int index = name.IndexOf('\0');
                 if (index > -1)
                 {
@@ -1183,7 +1183,7 @@ namespace System.Drawing.Printing
         private static string ReadOneDEVNAME(IntPtr pDevnames, int slot)
         {
             int offset = checked(Marshal.SystemDefaultCharSize * Marshal.ReadInt16((IntPtr)(checked((long)pDevnames + slot * 2))));
-            string result = Marshal.PtrToStringAuto((IntPtr)(checked((long)pDevnames + offset)));
+            string result = Marshal.PtrToStringAuto((IntPtr)(checked((long)pDevnames + offset)))!;
             return result;
         }
 
@@ -1196,7 +1196,7 @@ namespace System.Drawing.Printing
                 throw new ArgumentException(SR.Format(SR.InvalidPrinterHandle, hdevmode));
 
             IntPtr pointer = Interop.Kernel32.GlobalLock(hdevmode);
-            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));
+            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE))!;
 
             //Copy entire public devmode as a byte array...
             _devmodebytes = mode.dmSize;
@@ -1657,7 +1657,7 @@ namespace System.Drawing.Printing
             private readonly object[] _array;
             private readonly int _endIndex;
             private int _index;
-            private object _item;
+            private object? _item;
 
             public ArrayEnumerator(object[] array, int count)
             {
@@ -1665,7 +1665,7 @@ namespace System.Drawing.Printing
                 _endIndex = count;
             }
 
-            public object Current => _item;
+            public object? Current => _item;
 
             public bool MoveNext()
             {
index 98d87f5..c9da109 100644 (file)
@@ -49,7 +49,7 @@ namespace System.Drawing.Printing
 
         private static readonly bool s_cupsInitialized = CheckCupsInstalled();
         private static readonly Hashtable s_docInfo = Hashtable.Synchronized(new Hashtable());
-        private static Tuple<string, Dictionary<string, SysPrn.Printer>> s_printers; // cached default printer name and collection of all printers from cups
+        private static Tuple<string, Dictionary<string, SysPrn.Printer>>? s_printers; // cached default printer name and collection of all printers from cups
 
         #endregion
 
@@ -106,7 +106,7 @@ namespace System.Drawing.Printing
             try
             {
                 IntPtr ptr = LibcupsNative.cupsGetPPD(printer);
-                string ppd_filename = Marshal.PtrToStringAnsi(ptr);
+                string ppd_filename = Marshal.PtrToStringAnsi(ptr)!;
                 IntPtr ppd_handle = LibcupsNative.ppdOpenFile(ppd_filename);
                 return ppd_handle;
             }
@@ -181,10 +181,10 @@ namespace System.Drawing.Printing
 
             Dictionary<string, SysPrn.Printer> printers = EnsurePrintersInitialized().Item2;
 
-            if (!printers.TryGetValue(printer, out SysPrn.Printer p))
+            if (!printers.TryGetValue(printer, out SysPrn.Printer? p))
                 return;
 
-            PrinterSettings currentSettings = p.Settings;
+            PrinterSettings? currentSettings = p.Settings;
             if (currentSettings != null)
             {
                 settings.can_duplex = currentSettings.can_duplex;
@@ -219,7 +219,7 @@ namespace System.Drawing.Printing
                 for (int i = 0; i < ret; i++)
                 {
                     ptr_printer = (IntPtr)Marshal.ReadIntPtr(ptr);
-                    if (Marshal.PtrToStringAnsi(ptr_printer).Equals(printer))
+                    if (Marshal.PtrToStringAnsi(ptr_printer)!.Equals(printer))
                     {
                         name = printer;
                         break;
@@ -236,12 +236,12 @@ namespace System.Drawing.Printing
                 if (ppd_handle == IntPtr.Zero)
                     return;
 
-                printer_dest = (CUPS_DESTS)Marshal.PtrToStructure(ptr, typeof(CUPS_DESTS));
+                printer_dest = (CUPS_DESTS)Marshal.PtrToStructure(ptr, typeof(CUPS_DESTS))!;
                 options = new NameValueCollection();
                 paper_names = new NameValueCollection();
                 paper_sources = new NameValueCollection();
-                string defsize;
-                string defsource;
+                string? defsize;
+                string? defsource;
                 LoadPrinterOptions(printer_dest.options, printer_dest.num_options, ppd_handle, options,
                     paper_names, out defsize,
                     paper_sources, out defsource);
@@ -256,11 +256,11 @@ namespace System.Drawing.Printing
                 else
                     settings.paper_sources.Clear();
 
-                settings.DefaultPageSettings.PaperSource = LoadPrinterPaperSources(settings, defsource, paper_sources);
+                settings.DefaultPageSettings.PaperSource = LoadPrinterPaperSources(settings, defsource, paper_sources)!;
                 settings.DefaultPageSettings.PaperSize = LoadPrinterPaperSizes(ppd_handle, settings, defsize, paper_names);
                 LoadPrinterResolutionsAndDefault(printer, settings, ppd_handle);
 
-                ppd = (PPD_FILE)Marshal.PtrToStructure(ppd_handle, typeof(PPD_FILE));
+                ppd = (PPD_FILE)Marshal.PtrToStructure(ppd_handle, typeof(PPD_FILE))!;
                 settings.landscape_angle = ppd.landscape;
                 settings.supports_color = (ppd.color_device == 0) ? false : true;
                 settings.can_duplex = options["Duplex"] != null;
@@ -289,11 +289,11 @@ namespace System.Drawing.Printing
         /// <param name="defsource">The default source tray, set by LoadOptionList</param>
         private static void LoadPrinterOptions(IntPtr options, int numOptions, IntPtr ppd,
                                          NameValueCollection list,
-                                         NameValueCollection paper_names, out string defsize,
-                                         NameValueCollection paper_sources, out string defsource)
+                                         NameValueCollection paper_names, out string? defsize,
+                                         NameValueCollection paper_sources, out string? defsource)
         {
             CUPS_OPTIONS cups_options;
-            string option_name, option_value;
+            string? option_name, option_value;
             int cups_size = Marshal.SizeOf(typeof(CUPS_OPTIONS));
 
             LoadOptionList(ppd, "PageSize", paper_names, out defsize);
@@ -301,7 +301,7 @@ namespace System.Drawing.Printing
 
             for (int j = 0; j < numOptions; j++)
             {
-                cups_options = (CUPS_OPTIONS)Marshal.PtrToStructure(options, typeof(CUPS_OPTIONS));
+                cups_options = (CUPS_OPTIONS)Marshal.PtrToStructure(options, typeof(CUPS_OPTIONS))!;
                 option_name = Marshal.PtrToStringAnsi(cups_options.name);
                 option_value = Marshal.PtrToStringAnsi(cups_options.val);
 
@@ -327,12 +327,12 @@ namespace System.Drawing.Printing
         private static NameValueCollection LoadPrinterOptions(IntPtr options, int numOptions)
         {
             CUPS_OPTIONS cups_options;
-            string option_name, option_value;
+            string? option_name, option_value;
             int cups_size = Marshal.SizeOf(typeof(CUPS_OPTIONS));
             NameValueCollection list = new NameValueCollection();
             for (int j = 0; j < numOptions; j++)
             {
-                cups_options = (CUPS_OPTIONS)Marshal.PtrToStructure(options, typeof(CUPS_OPTIONS));
+                cups_options = (CUPS_OPTIONS)Marshal.PtrToStructure(options, typeof(CUPS_OPTIONS))!;
                 option_name = Marshal.PtrToStringAnsi(cups_options.name);
                 option_value = Marshal.PtrToStringAnsi(cups_options.val);
 
@@ -355,7 +355,7 @@ namespace System.Drawing.Printing
         /// <param name="option_name">Name of the option group to load</param>
         /// <param name="list">List of loaded options</param>
         /// <param name="defoption">The default option from the loaded options list</param>
-        private static void LoadOptionList(IntPtr ppd, string option_name, NameValueCollection list, out string defoption)
+        private static void LoadOptionList(IntPtr ppd, string option_name, NameValueCollection list, out string? defoption)
         {
 
             IntPtr ptr = IntPtr.Zero;
@@ -367,7 +367,7 @@ namespace System.Drawing.Printing
             ptr = LibcupsNative.ppdFindOption(ppd, option_name);
             if (ptr != IntPtr.Zero)
             {
-                ppd_option = (PPD_OPTION)Marshal.PtrToStructure(ptr, typeof(PPD_OPTION));
+                ppd_option = (PPD_OPTION)Marshal.PtrToStructure(ptr, typeof(PPD_OPTION))!;
 #if PrintDebug
                 Console.WriteLine (" OPTION  key:{0} def:{1} text: {2}", ppd_option.keyword, ppd_option.defchoice, ppd_option.text);
 #endif
@@ -375,7 +375,7 @@ namespace System.Drawing.Printing
                 ptr = ppd_option.choices;
                 for (int c = 0; c < ppd_option.num_choices; c++)
                 {
-                    choice = (PPD_CHOICE)Marshal.PtrToStructure(ptr, typeof(PPD_CHOICE));
+                    choice = (PPD_CHOICE)Marshal.PtrToStructure(ptr, typeof(PPD_CHOICE))!;
                     list.Add(choice.choice, choice.text);
 #if PrintDebug
                     Console.WriteLine ("       choice:{0} - text: {1}", choice.choice, choice.text);
@@ -406,7 +406,7 @@ namespace System.Drawing.Printing
         /// Create a PrinterResolution from a string Resolution that is set in the PPD option.
         /// An example of Resolution is "600x600dpi" or "600dpi". Returns null if malformed or "Unknown".
         /// </summary>
-        private static PrinterResolution ParseResolution(string resolution)
+        private static PrinterResolution? ParseResolution(string? resolution)
         {
             if (string.IsNullOrEmpty(resolution))
                 return null;
@@ -450,7 +450,7 @@ namespace System.Drawing.Printing
         /// <param name="def_size">Default paper size, from the global options of the printer</param>
         /// <param name="paper_names">List of available paper sizes that gets filled</param>
         private static PaperSize LoadPrinterPaperSizes(IntPtr ppd_handle, PrinterSettings settings,
-                                                string def_size, NameValueCollection paper_names)
+                                                string? def_size, NameValueCollection paper_names)
         {
             IntPtr ptr;
             string real_name;
@@ -459,13 +459,13 @@ namespace System.Drawing.Printing
             PaperSize ps;
 
             PaperSize defsize = new PaperSize(GetPaperKind(827, 1169), "A4", 827, 1169);
-            ppd = (PPD_FILE)Marshal.PtrToStructure(ppd_handle, typeof(PPD_FILE));
+            ppd = (PPD_FILE)Marshal.PtrToStructure(ppd_handle, typeof(PPD_FILE))!;
             ptr = ppd.sizes;
             float w, h;
             for (int i = 0; i < ppd.num_sizes; i++)
             {
-                size = (PPD_SIZE)Marshal.PtrToStructure(ptr, typeof(PPD_SIZE));
-                real_name = paper_names[size.name];
+                size = (PPD_SIZE)Marshal.PtrToStructure(ptr, typeof(PPD_SIZE))!;
+                real_name = paper_names[size.name]!;
                 w = size.width * 100 / 72;
                 h = size.length * 100 / 72;
                 PaperKind kind = GetPaperKind((int)w, (int)h);
@@ -473,7 +473,7 @@ namespace System.Drawing.Printing
                 ps.RawKind = (int)kind;
                 if (def_size == ps.Kind.ToString())
                     defsize = ps;
-                settings.paper_sizes.Add(ps);
+                settings.paper_sizes!.Add(ps);
                 ptr = (IntPtr)((long)ptr + Marshal.SizeOf(size));
             }
 
@@ -487,12 +487,12 @@ namespace System.Drawing.Printing
         /// <param name="settings">PrinterSettings object to fill</param>
         /// <param name="def_source">Default paper source, from the global options of the printer</param>
         /// <param name="paper_sources">List of available paper sizes that gets filled</param>
-        private static PaperSource LoadPrinterPaperSources(PrinterSettings settings, string def_source,
+        private static PaperSource? LoadPrinterPaperSources(PrinterSettings settings, string? def_source,
                                                     NameValueCollection paper_sources)
         {
             PaperSourceKind kind;
-            PaperSource defsource = null;
-            foreach (string source in paper_sources)
+            PaperSource? defsource = null;
+            foreach (string? source in paper_sources)
             {
                 switch (source)
                 {
@@ -515,12 +515,12 @@ namespace System.Drawing.Printing
                         kind = PaperSourceKind.Custom;
                         break;
                 }
-                settings.paper_sources.Add(new PaperSource(kind, paper_sources[source]));
+                settings.paper_sources!.Add(new PaperSource(kind, paper_sources[source]!));
                 if (def_source == source)
                     defsource = settings.paper_sources[settings.paper_sources.Count - 1];
             }
 
-            if (defsource == null && settings.paper_sources.Count > 0)
+            if (defsource == null && settings.paper_sources!.Count > 0)
                 return settings.paper_sources[0];
             return defsource;
         }
@@ -538,18 +538,18 @@ namespace System.Drawing.Printing
                 settings.printer_resolutions.Clear();
 
             var printer_resolutions = new NameValueCollection();
-            string defresolution;
+            string? defresolution;
             LoadOptionList(ppd_handle, "Resolution", printer_resolutions, out defresolution);
             foreach (var resolution in printer_resolutions.Keys)
             {
-                var new_resolution = ParseResolution(resolution.ToString());
+                var new_resolution = ParseResolution(resolution!.ToString());
                 settings.PrinterResolutions.Add(new_resolution);
             }
 
             var default_resolution = ParseResolution(defresolution);
 
             if (default_resolution == null)
-                default_resolution = ParseResolution("300dpi");
+                default_resolution = ParseResolution("300dpi")!;
             if (printer_resolutions.Count == 0)
                 settings.PrinterResolutions.Add(default_resolution);
 
@@ -576,8 +576,8 @@ namespace System.Drawing.Printing
                         IntPtr ptr_printers = dests;
                         for (int i = 0; i < n_printers; i++)
                         {
-                            var printer = (CUPS_DESTS)Marshal.PtrToStructure(ptr_printers, typeof(CUPS_DESTS));
-                            string name = Marshal.PtrToStringAnsi(printer.name);
+                            var printer = (CUPS_DESTS)Marshal.PtrToStructure(ptr_printers, typeof(CUPS_DESTS))!;
+                            string name = Marshal.PtrToStringAnsi(printer.name)!;
 
                             if (printer.is_default == 1 ||
                                 string.IsNullOrEmpty(defaultPrinterName))
@@ -648,7 +648,7 @@ namespace System.Drawing.Printing
                 for (int i = 0; i < count; i++)
                 {
                     ptr_printer = (IntPtr)Marshal.ReadIntPtr(ptr_printers);
-                    if (Marshal.PtrToStringAnsi(ptr_printer).Equals(printer))
+                    if (Marshal.PtrToStringAnsi(ptr_printer)!.Equals(printer))
                     {
                         found = true;
                         break;
@@ -659,15 +659,17 @@ namespace System.Drawing.Printing
                 if (!found)
                     return;
 
-                cups_dests = (CUPS_DESTS)Marshal.PtrToStructure(ptr_printers, typeof(CUPS_DESTS));
+                cups_dests = (CUPS_DESTS)Marshal.PtrToStructure(ptr_printers, typeof(CUPS_DESTS))!;
 
                 NameValueCollection options = LoadPrinterOptions(cups_dests.options, cups_dests.num_options);
 
                 if (options["printer-state"] != null)
-                    state = int.Parse(options["printer-state"]);
+                    // TODO-NULLABLE dotnet/roslyn#34644
+                    state = int.Parse(options["printer-state"]!);
 
                 if (options["printer-comment"] != null)
-                    comment = options["printer-state"];
+                    // TODO-NULLABLE dotnet/roslyn#34644
+                    comment = options["printer-state"]!;
 
                 switch (state)
                 {
@@ -773,7 +775,7 @@ namespace System.Drawing.Printing
 
         #region Print job methods
 
-        private static string tmpfile;
+        private static string? tmpfile;
 
         /// <summary>
         /// Gets a pointer to an options list parsed from the printer's current settings, to use when setting up the printing job
@@ -813,16 +815,16 @@ namespace System.Drawing.Printing
 
         internal static bool StartDoc(GraphicsPrinter gr, string doc_name, string output_file)
         {
-            DOCINFO doc = (DOCINFO)s_docInfo[gr.Hdc];
+            DOCINFO doc = (DOCINFO)s_docInfo[gr.Hdc]!;
             doc.title = doc_name;
             return true;
         }
 
         internal static bool EndDoc(GraphicsPrinter gr)
         {
-            DOCINFO doc = (DOCINFO)s_docInfo[gr.Hdc];
+            DOCINFO doc = (DOCINFO)s_docInfo[gr.Hdc]!;
 
-            gr.Graphics.Dispose(); // Dispose object to force surface finish
+            gr.Graphics!.Dispose(); // Dispose object to force surface finish
 
             IntPtr options;
             int options_count = GetCupsOptions(doc.settings, doc.default_page_settings, out options);
@@ -855,7 +857,7 @@ namespace System.Drawing.Printing
         internal static IntPtr CreateGraphicsContext(PrinterSettings settings, PageSettings default_page_settings)
         {
             IntPtr graphics = IntPtr.Zero;
-            string name;
+            string? name;
             if (!settings.PrintToFile)
             {
                 StringBuilder sb = new StringBuilder(1024);
@@ -865,7 +867,7 @@ namespace System.Drawing.Printing
                 tmpfile = name;
             }
             else
-                name = settings.PrintFileName;
+                name = settings.PrintFileName!;
 
             PaperSize psize = default_page_settings.PaperSize;
             int width, height;
@@ -1033,7 +1035,7 @@ namespace System.Drawing.Printing
             public readonly string Port;
             public readonly string Type;
             public readonly string Status;
-            public PrinterSettings Settings;
+            public PrinterSettings? Settings;
 
             public Printer(string port, string type, string status, string comment)
             {
@@ -1047,16 +1049,16 @@ namespace System.Drawing.Printing
 
     internal class GraphicsPrinter
     {
-        private Graphics graphics;
+        private Graphics? graphics;
         private IntPtr hDC;
 
-        internal GraphicsPrinter(Graphics gr, IntPtr dc)
+        internal GraphicsPrinter(Graphics? gr, IntPtr dc)
         {
             graphics = gr;
             hDC = dc;
         }
 
-        internal Graphics Graphics
+        internal Graphics? Graphics
         {
             get { return graphics; }
             set { graphics = value; }
index 15fed0b..5cf4378 100644 (file)
@@ -46,7 +46,7 @@ namespace System.Drawing.Printing
 
         public override void OnEndPage(PrintDocument document, PrintPageEventArgs e)
         {
-            PrintingServices.EndPage(e.GraphicsContext);
+            PrintingServices.EndPage(e.GraphicsContext!);
         }
 
         public override void OnStartPrint(PrintDocument document, PrintEventArgs e)
@@ -58,12 +58,12 @@ namespace System.Drawing.Printing
 
         public override void OnEndPrint(PrintDocument document, PrintEventArgs e)
         {
-            PrintingServices.EndDoc(e.GraphicsContext);
+            PrintingServices.EndDoc(e.GraphicsContext!);
         }
 
-        public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e)
+        public override Graphics? OnStartPage(PrintDocument document, PrintPageEventArgs e)
         {
-            PrintingServices.StartPage(e.GraphicsContext);
+            PrintingServices.StartPage(e.GraphicsContext!);
             return e.Graphics;
         }
     }
index 0ad9933..c113dc1 100644 (file)
@@ -47,9 +47,9 @@ namespace System.Drawing.Printing
             return !(left == right);
         }
 
-        public override bool Equals(object o)
+        public override bool Equals(object? o)
         {
-            TriState state = (TriState)o;
+            TriState state = (TriState)o!;
             return _value == state._value;
         }
 
index 1bc6c4e..4b4c04f 100644 (file)
@@ -50,7 +50,7 @@ namespace System.Drawing.Imaging
             propItemInternal.len = 0;
             propItemInternal.type = propItem.Type;
 
-            byte[] propItemValue = propItem.Value;
+            byte[]? propItemValue = propItem.Value;
             if (propItemValue != null)
             {
                 int length = propItemValue.Length;
@@ -68,11 +68,11 @@ namespace System.Drawing.Imaging
 
             for (int i = 0; i < count; i++)
             {
-                PropertyItemInternal propcopy = null;
+                PropertyItemInternal? propcopy = null;
                 try
                 {
                     propcopy = (PropertyItemInternal)Marshal.PtrToStructure(propdata,
-                                                  typeof(PropertyItemInternal));
+                                                  typeof(PropertyItemInternal))!;
 
                     props[i] = new PropertyItem();
                     props[i].Id = propcopy.id;
@@ -98,7 +98,7 @@ namespace System.Drawing.Imaging
             return props;
         }
 
-        public byte[] Value
+        public byte[]? Value
         {
             get
             {
index 8a73061..125c372 100644 (file)
@@ -330,7 +330,7 @@ namespace System.Drawing
             return isEqual != 0;
         }
 
-        public RegionData GetRegionData()
+        public RegionData? GetRegionData()
         {
             Gdip.CheckStatus(Gdip.GdipGetRegionDataSize(new HandleRef(this, NativeRegion), out int regionSize));
 
@@ -346,9 +346,9 @@ namespace System.Drawing
 
         public bool IsVisible(PointF point) => IsVisible(point, null);
 
-        public bool IsVisible(float x, float y, Graphics g) => IsVisible(new PointF(x, y), g);
+        public bool IsVisible(float x, float y, Graphics? g) => IsVisible(new PointF(x, y), g);
 
-        public bool IsVisible(PointF point, Graphics g)
+        public bool IsVisible(PointF point, Graphics? g)
         {
             Gdip.CheckStatus(Gdip.GdipIsVisibleRegionPoint(
                 new HandleRef(this, NativeRegion),
@@ -363,9 +363,9 @@ namespace System.Drawing
 
         public bool IsVisible(RectangleF rect) => IsVisible(rect, null);
 
-        public bool IsVisible(float x, float y, float width, float height, Graphics g) => IsVisible(new RectangleF(x, y, width, height), g);
+        public bool IsVisible(float x, float y, float width, float height, Graphics? g) => IsVisible(new RectangleF(x, y, width, height), g);
 
-        public bool IsVisible(RectangleF rect, Graphics g)
+        public bool IsVisible(RectangleF rect, Graphics? g)
         {
             Gdip.CheckStatus(Gdip.GdipIsVisibleRegionRect(
                 new HandleRef(this, NativeRegion),
@@ -376,11 +376,11 @@ namespace System.Drawing
             return isVisible != 0;
         }
 
-        public bool IsVisible(int x, int y, Graphics g) => IsVisible(new Point(x, y), g);
+        public bool IsVisible(int x, int y, Graphics? g) => IsVisible(new Point(x, y), g);
 
         public bool IsVisible(Point point) => IsVisible(point, null);
 
-        public bool IsVisible(Point point, Graphics g)
+        public bool IsVisible(Point point, Graphics? g)
         {
             Gdip.CheckStatus(Gdip.GdipIsVisibleRegionPointI(
                 new HandleRef(this, NativeRegion),
@@ -395,9 +395,9 @@ namespace System.Drawing
 
         public bool IsVisible(Rectangle rect) => IsVisible(rect, null);
 
-        public bool IsVisible(int x, int y, int width, int height, Graphics g) => IsVisible(new Rectangle(x, y, width, height), g);
+        public bool IsVisible(int x, int y, int width, int height, Graphics? g) => IsVisible(new Rectangle(x, y, width, height), g);
 
-        public bool IsVisible(Rectangle rect, Graphics g)
+        public bool IsVisible(Rectangle rect, Graphics? g)
         {
             Gdip.CheckStatus(Gdip.GdipIsVisibleRegionRectI(
                 new HandleRef(this, NativeRegion),
index 66c254d..ce26806 100644 (file)
@@ -61,7 +61,7 @@ namespace System.Drawing
                 throw new ArgumentException(SR.Format(SR.ColorNotSystemColor, c.ToString()));
             }
 
-            Brush[] systemBrushes = (Brush[])Gdip.ThreadData[s_systemBrushesKey];
+            Brush[]? systemBrushes = (Brush[]?)Gdip.ThreadData[s_systemBrushesKey];
             if (systemBrushes == null)
             {
                 systemBrushes = new Brush[(int)KnownColor.WindowText + (int)KnownColor.MenuHighlight - (int)KnownColor.YellowGreen];
index f8252f1..004e6b5 100644 (file)
@@ -19,11 +19,11 @@ namespace System.Drawing
             }
         }
 
-        public static Font CaptionFont
+        public static Font? CaptionFont
         {
             get
             {
-                Font captionFont = null;
+                Font? captionFont = null;
 
                 if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
                 {
@@ -35,11 +35,11 @@ namespace System.Drawing
             }
         }
 
-        public static Font SmallCaptionFont
+        public static Font? SmallCaptionFont
         {
             get
             {
-                Font smcaptionFont = null;
+                Font? smcaptionFont = null;
 
                 if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
                 {
@@ -51,11 +51,11 @@ namespace System.Drawing
             }
         }
 
-        public static Font MenuFont
+        public static Font? MenuFont
         {
             get
             {
-                Font menuFont = null;
+                Font? menuFont = null;
 
                 if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
                 {
@@ -67,11 +67,11 @@ namespace System.Drawing
             }
         }
 
-        public static Font StatusFont
+        public static Font? StatusFont
         {
             get
             {
-                Font statusFont = null;
+                Font? statusFont = null;
 
                 if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
                 {
@@ -83,11 +83,11 @@ namespace System.Drawing
             }
         }
 
-        public static Font MessageBoxFont
+        public static Font? MessageBoxFont
         {
             get
             {
-                Font messageBoxFont = null;
+                Font? messageBoxFont = null;
 
                 if (GetNonClientMetrics(out Interop.User32.NONCLIENTMETRICS metrics))
                 {
@@ -111,11 +111,11 @@ namespace System.Drawing
                 ex is FileNotFoundException);
         }
 
-        public static unsafe Font IconTitleFont
+        public static unsafe Font? IconTitleFont
         {
             get
             {
-                Font iconTitleFont = null;
+                Font? iconTitleFont = null;
 
                 Interop.User32.LOGFONT itfont = default;
                 if (Interop.User32.SystemParametersInfoW(Interop.User32.SystemParametersAction.SPI_GETICONTITLELOGFONT, (uint)sizeof(Interop.User32.LOGFONT), &itfont, 0))
@@ -132,7 +132,7 @@ namespace System.Drawing
         {
             get
             {
-                Font defaultFont = null;
+                Font? defaultFont = null;
 
                 // For Arabic systems, always return Tahoma 8.
                 if ((ushort)UnsafeNativeMethods.GetSystemDefaultLCID() == 0x0001)
@@ -195,7 +195,7 @@ namespace System.Drawing
         {
             get
             {
-                Font dialogFont = null;
+                Font? dialogFont = null;
 
                 if ((ushort)UnsafeNativeMethods.GetSystemDefaultLCID() == 0x0011)
                 {
@@ -226,7 +226,7 @@ namespace System.Drawing
 
                 // For Japanese cultures, SystemFonts.DefaultFont returns a new Font object every time it is invoked.
                 // So for Japanese we return the DefaultFont with its SystemFontName set to DialogFont.
-                dialogFont.SetSystemFontName(nameof(DialogFont));
+                dialogFont!.SetSystemFontName(nameof(DialogFont));
                 return dialogFont;
             }
         }
@@ -238,7 +238,7 @@ namespace System.Drawing
 
         private static Font GetFontFromData(Interop.User32.LOGFONT logFont)
         {
-            Font font = null;
+            Font? font = null;
             try
             {
                 font = Font.FromLogFont(ref logFont);
index ed33d0b..ee21f87 100644 (file)
@@ -10,7 +10,7 @@ namespace System.Drawing
 {
     public static partial class SystemFonts
     {
-        public static Font GetFontByName(string systemFontName)
+        public static Font? GetFontByName(string systemFontName)
         {
             if (nameof(CaptionFont).Equals(systemFontName))
             {
index 101625a..287279c 100644 (file)
@@ -8,16 +8,16 @@ namespace System.Drawing
 {
     public static class SystemIcons
     {
-        private static Icon s_application = null;
-        private static Icon s_asterisk = null;
-        private static Icon s_error = null;
-        private static Icon s_exclamation = null;
-        private static Icon s_hand = null;
-        private static Icon s_information = null;
-        private static Icon s_question = null;
-        private static Icon s_warning = null;
-        private static Icon s_winlogo = null;
-        private static Icon s_shield = null;
+        private static Icon? s_application = null;
+        private static Icon? s_asterisk = null;
+        private static Icon? s_error = null;
+        private static Icon? s_exclamation = null;
+        private static Icon? s_hand = null;
+        private static Icon? s_information = null;
+        private static Icon? s_question = null;
+        private static Icon? s_warning = null;
+        private static Icon? s_winlogo = null;
+        private static Icon? s_shield = null;
 
         public static Icon Application => GetIcon(ref s_application, SafeNativeMethods.IDI_APPLICATION);
 
@@ -51,7 +51,7 @@ namespace System.Drawing
             }
         }
 
-        private static Icon GetIcon(ref Icon icon, int iconId)
+        private static Icon GetIcon(ref Icon? icon, int iconId)
         {
             return icon ?? (icon = new Icon(SafeNativeMethods.LoadIcon(NativeMethods.NullHandleRef, (IntPtr)iconId)));
         }
index 81c1121..e4d9af3 100644 (file)
@@ -62,7 +62,7 @@ namespace System.Drawing
                 throw new ArgumentException(SR.Format(SR.ColorNotSystemColor, c.ToString()));
             }
 
-            Pen[] systemPens = (Pen[])Gdip.ThreadData[s_systemPensKey];
+            Pen[]? systemPens = (Pen[]?)Gdip.ThreadData[s_systemPensKey];
             if (systemPens == null)
             {
                 systemPens = new Pen[(int)KnownColor.WindowText + (int)KnownColor.MenuHighlight - (int)KnownColor.YellowGreen];
index 90fe6a5..fbe0b0f 100644 (file)
@@ -96,7 +96,7 @@ namespace System.Drawing
 
         public TextureBrush(Image image, RectangleF dstRect) : this(image, dstRect, null) { }
 
-        public TextureBrush(Image image, RectangleF dstRect, ImageAttributes imageAttr)
+        public TextureBrush(Image image, RectangleF dstRect, ImageAttributes? imageAttr)
         {
             if (image == null)
             {
@@ -119,7 +119,7 @@ namespace System.Drawing
 
         public TextureBrush(Image image, Rectangle dstRect) : this(image, dstRect, null) { }
 
-        public TextureBrush(Image image, Rectangle dstRect, ImageAttributes imageAttr)
+        public TextureBrush(Image image, Rectangle dstRect, ImageAttributes? imageAttr)
         {
             if (image == null)
             {
index 42e48a6..8269301 100644 (file)
@@ -42,8 +42,8 @@ namespace System.Drawing
     [AttributeUsage(AttributeTargets.Class)]
     public class ToolboxBitmapAttribute : Attribute
     {
-        private Image smallImage = null;
-        private Image bigImage = null;
+        private Image? smallImage = null;
+        private Image? bigImage = null;
         public static readonly ToolboxBitmapAttribute Default = new ToolboxBitmapAttribute();
 
         private ToolboxBitmapAttribute()
@@ -64,7 +64,7 @@ namespace System.Drawing
             smallImage = GetImageFromResource(t, name, false);
         }
 
-        public override bool Equals(object value)
+        public override bool Equals(object? value)
         {
             if (!(value is ToolboxBitmapAttribute))
                 return false;
@@ -75,30 +75,30 @@ namespace System.Drawing
 
         public override int GetHashCode()
         {
-            return (smallImage.GetHashCode() ^ bigImage.GetHashCode());
+            return (smallImage!.GetHashCode() ^ bigImage!.GetHashCode());
         }
 
-        public Image GetImage(object component)
+        public Image? GetImage(object component)
         {
             return GetImage(component.GetType(), null, false);
         }
 
-        public Image GetImage(object component, bool large)
+        public Image? GetImage(object component, bool large)
         {
             return GetImage(component.GetType(), null, large);
         }
 
-        public Image GetImage(Type type)
+        public Image? GetImage(Type type)
         {
             return GetImage(type, null, false);
         }
 
-        public Image GetImage(Type type, bool large)
+        public Image? GetImage(Type type, bool large)
         {
             return GetImage(type, null, large);
         }
 
-        public Image GetImage(Type type, string imgName, bool large)
+        public Image? GetImage(Type type, string? imgName, bool large)
         {
             if (smallImage == null)
                 smallImage = GetImageFromResource(type, imgName, false);
@@ -106,14 +106,14 @@ namespace System.Drawing
             if (large)
             {
                 if (bigImage == null)
-                    bigImage = new Bitmap(smallImage, 32, 32);
+                    bigImage = new Bitmap(smallImage!, 32, 32);
                 return bigImage;
             }
             else
                 return smallImage;
         }
 
-        public static Image GetImageFromResource(Type t, string imageName, bool large)
+        public static Image? GetImageFromResource(Type t, string? imageName, bool large)
         {
             Bitmap bitmap;
             if (imageName == null)
@@ -121,7 +121,7 @@ namespace System.Drawing
 
             try
             {
-                using (System.IO.Stream s = t.GetTypeInfo().Assembly.GetManifestResourceStream(t.Namespace + "." + imageName))
+                using (System.IO.Stream? s = t.GetTypeInfo().Assembly.GetManifestResourceStream(t.Namespace + "." + imageName))
                 {
                     if (s == null)
                     {
index 2befc6e..a8b4894 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 using System.Drawing.Imaging;
 using System.IO;
 using DpiHelper = System.Windows.Forms.DpiHelper;
@@ -17,20 +18,20 @@ namespace System.Drawing
     [AttributeUsage(AttributeTargets.Class)]
     public class ToolboxBitmapAttribute : Attribute
     {
-        private Image _smallImage;
-        private Image _largeImage;
+        private Image? _smallImage;
+        private Image? _largeImage;
 
-        private readonly string _imageFile;
-        private readonly Type _imageType;
+        private readonly string? _imageFile;
+        private readonly Type? _imageType;
 
-        private readonly string _imageName;
+        private readonly string? _imageName;
 
         private static readonly Size s_largeSize = new Size(32, 32);
         private static readonly Size s_smallSize = new Size(16, 16);
 
         // Used to help cache the last result of BitmapSelector.GetFileName.
-        private static string s_lastOriginalFileName;
-        private static string s_lastUpdatedFileName;
+        private static string? s_lastOriginalFileName;
+        private static string? s_lastUpdatedFileName;
 
         public ToolboxBitmapAttribute(string imageFile) : this(GetImageFromFile(imageFile, false), GetImageFromFile(imageFile, true))
         {
@@ -49,13 +50,13 @@ namespace System.Drawing
             _imageName = name;
         }
 
-        private ToolboxBitmapAttribute(Image smallImage, Image largeImage)
+        private ToolboxBitmapAttribute(Image? smallImage, Image? largeImage)
         {
             _smallImage = smallImage;
             _largeImage = largeImage;
         }
 
-        public override bool Equals(object value)
+        public override bool Equals(object? value)
         {
             if (value == this)
             {
@@ -72,9 +73,9 @@ namespace System.Drawing
 
         public override int GetHashCode() => base.GetHashCode();
 
-        public Image GetImage(object component) => GetImage(component, true);
+        public Image? GetImage(object? component) => GetImage(component, true);
 
-        public Image GetImage(object component, bool large)
+        public Image? GetImage(object? component, bool large)
         {
             if (component != null)
             {
@@ -84,15 +85,15 @@ namespace System.Drawing
             return null;
         }
 
-        public Image GetImage(Type type) => GetImage(type, false);
+        public Image? GetImage(Type type) => GetImage(type, false);
 
-        public Image GetImage(Type type, bool large) => GetImage(type, null, large);
+        public Image? GetImage(Type type, bool large) => GetImage(type, null, large);
 
-        public Image GetImage(Type type, string imgName, bool large)
+        public Image? GetImage(Type type, string? imgName, bool large)
         {
             if ((large && _largeImage == null) || (!large && _smallImage == null))
             {
-                Image img = null;
+                Image? img = null;
                 if (large)
                 {
                     img = _largeImage;
@@ -140,7 +141,7 @@ namespace System.Drawing
                 }
             }
 
-            Image toReturn = (large) ? _largeImage : _smallImage;
+            Image? toReturn = (large) ? _largeImage : _smallImage;
 
             if (Equals(Default))
             {
@@ -152,7 +153,7 @@ namespace System.Drawing
         }
 
         // Helper to get the right icon from the given stream that represents an icon.
-        private static Image GetIconFromStream(Stream stream, bool large, bool scaled)
+        private static Image? GetIconFromStream(Stream? stream, bool large, bool scaled)
         {
             if (stream == null)
             {
@@ -160,7 +161,7 @@ namespace System.Drawing
             }
             Icon ico = new Icon(stream);
             Icon sizedico = new Icon(ico, large ? s_largeSize : s_smallSize);
-            Bitmap b = sizedico.ToBitmap();
+            Bitmap? b = sizedico.ToBitmap();
             if (DpiHelper.IsScalingRequired && scaled)
             {
                 DpiHelper.ScaleBitmapLogicalToDevice(ref b);
@@ -170,7 +171,7 @@ namespace System.Drawing
 
         // Cache the last result of BitmapSelector.GetFileName because we commonly load images twice
         // in succession from the same file and we don't need to compute the name twice.
-        private static string GetFileNameFromBitmapSelector(string originalName)
+        private static string? GetFileNameFromBitmapSelector(string originalName)
         {
             if (originalName != s_lastOriginalFileName)
             {
@@ -182,20 +183,20 @@ namespace System.Drawing
         }
 
         // Just forwards to Image.FromFile eating any non-critical exceptions that may result.
-        private static Image GetImageFromFile(string imageFile, bool large, bool scaled = true)
+        private static Image? GetImageFromFile(string? imageFile, bool large, bool scaled = true)
         {
-            Image image = null;
+            Image? image = null;
             try
             {
                 if (imageFile != null)
                 {
                     imageFile = GetFileNameFromBitmapSelector(imageFile);
 
-                    string ext = Path.GetExtension(imageFile);
+                    string? ext = Path.GetExtension(imageFile);
                     if (ext != null && string.Equals(ext, ".ico", StringComparison.OrdinalIgnoreCase))
                     {
                         //ico files support both large and small, so we respect the large flag here.
-                        using (FileStream reader = File.OpenRead(imageFile))
+                        using (FileStream reader = File.OpenRead(imageFile!))
                         {
                             image = GetIconFromStream(reader, large, scaled);
                         }
@@ -203,8 +204,8 @@ namespace System.Drawing
                     else if (!large)
                     {
                         //we only read small from non-ico files.
-                        image = Image.FromFile(imageFile);
-                        Bitmap b = image as Bitmap;
+                        image = Image.FromFile(imageFile!);
+                        Bitmap? b = image as Bitmap;
                         if (DpiHelper.IsScalingRequired && scaled)
                         {
                             DpiHelper.ScaleBitmapLogicalToDevice(ref b);
@@ -219,20 +220,20 @@ namespace System.Drawing
             return image;
         }
 
-        private static Image GetBitmapFromResource(Type t, string bitmapname, bool large, bool scaled)
+        private static Image? GetBitmapFromResource(Type t, string? bitmapname, bool large, bool scaled)
         {
             if (bitmapname == null)
             {
                 return null;
             }
 
-            Image img = null;
+            Image? img = null;
 
             // Load the image from the manifest resources.
-            Stream stream = BitmapSelector.GetResourceStream(t, bitmapname);
+            Stream? stream = BitmapSelector.GetResourceStream(t, bitmapname);
             if (stream != null)
             {
-                Bitmap b = new Bitmap(stream);
+                Bitmap? b = new Bitmap(stream);
                 img = b;
                 MakeBackgroundAlphaZero(b);
                 if (large)
@@ -249,7 +250,7 @@ namespace System.Drawing
             return img;
         }
 
-        private static Image GetIconFromResource(Type t, string bitmapname, bool large, bool scaled)
+        private static Image? GetIconFromResource(Type t, string? bitmapname, bool large, bool scaled)
         {
             if (bitmapname == null)
             {
@@ -259,25 +260,25 @@ namespace System.Drawing
             return GetIconFromStream(BitmapSelector.GetResourceStream(t, bitmapname), large, scaled);
         }
 
-        public static Image GetImageFromResource(Type t, string imageName, bool large)
+        public static Image? GetImageFromResource(Type t, string? imageName, bool large)
         {
             return GetImageFromResource(t, imageName, large, scaled: true);
         }
 
-        internal static Image GetImageFromResource(Type t, string imageName, bool large, bool scaled)
+        internal static Image? GetImageFromResource(Type t, string? imageName, bool large, bool scaled)
         {
-            Image img = null;
+            Image? img = null;
             try
             {
-                string name = imageName;
-                string iconname = null;
-                string bmpname = null;
-                string rawbmpname = null;
+                string? name = imageName;
+                string? iconname = null;
+                string? bmpname = null;
+                string? rawbmpname = null;
 
                 // If we didn't get a name, use the class name
                 if (name == null)
                 {
-                    name = t.FullName;
+                    name = t.FullName!;
                     int indexDot = name.LastIndexOf('.');
                     if (indexDot != -1)
                     {
@@ -341,7 +342,7 @@ namespace System.Drawing
             img.SetPixel(0, img.Height - 1, newBottomLeft);
         }
 
-        public static readonly ToolboxBitmapAttribute Default = new ToolboxBitmapAttribute(null, (Image)null);
+        public static readonly ToolboxBitmapAttribute Default = new ToolboxBitmapAttribute(null, (Image?)null);
 
         private static readonly ToolboxBitmapAttribute s_defaultComponent;
 
@@ -351,7 +352,7 @@ namespace System.Drawing
             // When we call Gdip.DummyFunction, JIT will make sure Gdip..cctor will be called.
             Gdip.DummyFunction();
 
-            Stream stream = BitmapSelector.GetResourceStream(typeof(ToolboxBitmapAttribute), "DefaultComponent.bmp");
+            Stream? stream = BitmapSelector.GetResourceStream(typeof(ToolboxBitmapAttribute), "DefaultComponent.bmp");
             Debug.Assert(stream != null, "DefaultComponent.bmp must be present as an embedded resource.");
 
             var bitmap = new Bitmap(stream);
index 7626221..229c032 100644 (file)
@@ -39,7 +39,7 @@ namespace System.Drawing
     {
         internal static readonly Hashtable contextReference = new Hashtable();
         internal static readonly object lockobj = new object();
-        internal static readonly Delegate hwnd_delegate = GetHwndDelegate();
+        internal static readonly Delegate? hwnd_delegate = GetHwndDelegate();
 
 #if DEBUG_CLIPPING
         internal static float red = 1.0f;
@@ -48,17 +48,17 @@ namespace System.Drawing
         internal static int debug_threshold = 1;
 #endif
 
-        private static Delegate GetHwndDelegate()
+        private static Delegate? GetHwndDelegate()
         {
 #if !NETSTANDARD1_6
             foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
             {
                 if (string.Equals(asm.GetName().Name, "System.Windows.Forms"))
                 {
-                    Type driver_type = asm.GetType("System.Windows.Forms.XplatUICarbon");
+                    Type? driver_type = asm.GetType("System.Windows.Forms.XplatUICarbon");
                     if (driver_type != null)
                     {
-                        return (Delegate)driver_type.GetTypeInfo().GetField("HwndDelegate", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
+                        return (Delegate?)driver_type.GetTypeInfo().GetField("HwndDelegate", BindingFlags.NonPublic | BindingFlags.Static)!.GetValue(null);
                     }
                 }
             }
@@ -130,7 +130,7 @@ namespace System.Drawing
 
             CGContextSaveGState(context);
 
-            Rectangle[] clip_rectangles = (Rectangle[])hwnd_delegate.DynamicInvoke(new object[] { handle });
+            Rectangle[]? clip_rectangles = (Rectangle[]?)hwnd_delegate!.DynamicInvoke(new object[] { handle });
             if (clip_rectangles != null && clip_rectangles.Length > 0)
             {
                 int length = clip_rectangles.Length;
index b6f8e54..a45b788 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Configuration;
+using System.Diagnostics.CodeAnalysis;
 using System.Drawing;
 using System.Drawing.Drawing2D;
 using System.Runtime.InteropServices;
@@ -194,7 +195,8 @@ namespace System.Windows.Forms
         /// </summary>
         /// <param name="logicalImage">The image to scale from logical units to device units</param>
         /// <param name="targetImageSize">The size to scale image to</param>
-        public static Bitmap CreateResizedBitmap(Bitmap logicalImage, Size targetImageSize)
+        [return: NotNullIfNotNull("logicalImage")]
+        public static Bitmap? CreateResizedBitmap(Bitmap? logicalImage, Size targetImageSize)
         {
             if (logicalImage == null)
             {
@@ -210,7 +212,7 @@ namespace System.Windows.Forms
         /// Note: this method should be called only inside an if (DpiHelper.IsScalingRequired) clause
         /// </summary>
         /// <param name="logicalBitmap">The image to scale from logical units to device units</param>
-        public static void ScaleBitmapLogicalToDevice(ref Bitmap logicalBitmap)
+        public static void ScaleBitmapLogicalToDevice([NotNullIfNotNull("logicalBitmap")]ref Bitmap? logicalBitmap)
         {
             if (logicalBitmap == null)
             {
index 48cbb93..40b45a3 100644 (file)
@@ -60,7 +60,7 @@ namespace System.Drawing.Internal
         private IntPtr _hDC;
         private readonly DeviceContextType _dcType;
 
-        public event EventHandler Disposing;
+        public event EventHandler? Disposing;
 
         private bool _disposed;
 
@@ -78,7 +78,7 @@ namespace System.Drawing.Internal
         private IntPtr _hCurrentBmp;
         private IntPtr _hCurrentFont;
 
-        private Stack _contextStack;
+        private Stack? _contextStack;
 
 #if GDI_FINALIZATION_WATCH
         private string AllocationSite = DbgUtil.StackTrace;
@@ -171,7 +171,7 @@ namespace System.Drawing.Internal
         /// <summary>
         /// CreateDC creates a DeviceContext object wrapping an hdc created with the Win32 CreateDC function.
         /// </summary>
-        public static DeviceContext CreateDC(string driverName, string deviceName, string fileName, IntPtr devMode)
+        public static DeviceContext CreateDC(string driverName, string deviceName, string? fileName, IntPtr devMode)
         {
             // Note: All input params can be null but not at the same time.  See MSDN for information.
             IntPtr hdc = Interop.Gdi32.CreateDCW(driverName, deviceName, fileName, devMode);
@@ -181,7 +181,7 @@ namespace System.Drawing.Internal
         /// <summary>
         /// CreateIC creates a DeviceContext object wrapping an hdc created with the Win32 CreateIC function.
         /// </summary>
-        public static DeviceContext CreateIC(string driverName, string deviceName, string fileName, IntPtr devMode)
+        public static DeviceContext CreateIC(string driverName, string deviceName, string? fileName, IntPtr devMode)
         {
             // Note: All input params can be null but not at the same time.  See MSDN for information.
 
@@ -330,7 +330,7 @@ namespace System.Drawing.Internal
 
             if (_contextStack != null)
             {
-                GraphicsState g = (GraphicsState)_contextStack.Pop();
+                GraphicsState g = (GraphicsState)_contextStack.Pop()!;
 
                 _hCurrentBmp = g.hBitmap;
                 _hCurrentBrush = g.hBrush;
@@ -437,9 +437,9 @@ namespace System.Drawing.Internal
 
         /// <summary>
         /// </summary>
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
-            DeviceContext other = obj as DeviceContext;
+            DeviceContext? other = obj as DeviceContext;
 
             if (other == this)
             {
index 1ccf5f1..e062cc9 100644 (file)
@@ -11,7 +11,7 @@ namespace System.Drawing.Internal
     internal static class DeviceContexts
     {
         [ThreadStatic]
-        private static ClientUtils.WeakRefCollection t_activeDeviceContexts;
+        private static ClientUtils.WeakRefCollection? t_activeDeviceContexts;
 
         /// <summary>
         /// WindowsGraphicsCacheManager needs to track DeviceContext objects so it can ask them if a font is in use
@@ -34,7 +34,7 @@ namespace System.Drawing.Internal
             }
         }
 
-        private static void OnDcDisposing(object sender, EventArgs e)
+        private static void OnDcDisposing(object? sender, EventArgs e)
         {
             if (sender is DeviceContext dc)
             {
index ae19f01..6743c88 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Drawing.Internal
         // Note: this dc is only disposed when owned (created) by the WindowsGraphics.
         private DeviceContext _dc;
         private bool _disposeDc;
-        private Graphics _graphics; // cached when initialized FromGraphics to be able to call g.ReleaseHdc from Dispose.
+        private Graphics? _graphics; // cached when initialized FromGraphics to be able to call g.ReleaseHdc from Dispose.
 
 #if GDI_FINALIZATION_WATCH
         private string AllocationSite = DbgUtil.StackTrace;
@@ -54,11 +54,11 @@ namespace System.Drawing.Internal
         {
             Debug.Assert(g != null, "null Graphics object.");
 
-            WindowsRegion wr = null;
-            float[] elements = null;
+            WindowsRegion? wr = null;
+            float[]? elements = null;
 
-            Region clipRgn = null;
-            Matrix worldTransf = null;
+            Region? clipRgn = null;
+            Matrix? worldTransf = null;
 
             if ((properties & ApplyGraphicsProperties.TranslateTransform) != 0 || (properties & ApplyGraphicsProperties.Clipping) != 0)
             {
@@ -162,7 +162,7 @@ namespace System.Drawing.Internal
                 }
                 finally
                 {
-                    _dc = null;
+                    _dc = null!;
                 }
             }
         }