Skip to content

Commit 7eeb1de

Browse files
committed
Remove !! from System.Drawing.Common.
1 parent b61661f commit 7eeb1de

18 files changed

+558
-177
lines changed

src/libraries/System.Drawing.Common/src/System/Drawing/Bitmap.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ public Bitmap(Stream stream) : this(stream, false)
5454
{
5555
}
5656

57-
public unsafe Bitmap(Stream stream!!, bool useIcm)
57+
public unsafe Bitmap(Stream stream, bool useIcm)
5858
{
59+
ArgumentNullException.ThrowIfNull(stream);
60+
5961
using DrawingCom.IStreamWrapper streamWrapper = DrawingCom.GetComWrapper(new GPStream(stream));
6062

6163
IntPtr bitmap = IntPtr.Zero;
@@ -78,8 +80,11 @@ public Bitmap(Type type, string resource) : this(GetResourceStream(type, resourc
7880
{
7981
}
8082

81-
private static Stream GetResourceStream(Type type!!, string resource!!)
83+
private static Stream GetResourceStream(Type type, string resource)
8284
{
85+
ArgumentNullException.ThrowIfNull(type);
86+
ArgumentNullException.ThrowIfNull(resource);
87+
8388
Stream? stream = type.Module.Assembly.GetManifestResourceStream(type, resource);
8489
if (stream == null)
8590
{
@@ -93,8 +98,10 @@ public Bitmap(int width, int height) : this(width, height, PixelFormat.Format32b
9398
{
9499
}
95100

96-
public Bitmap(int width, int height, Graphics g!!)
101+
public Bitmap(int width, int height, Graphics g)
97102
{
103+
ArgumentNullException.ThrowIfNull(g);
104+
98105
IntPtr bitmap;
99106
int status = Gdip.GdipCreateBitmapFromGraphics(width, height, new HandleRef(g, g.NativeGraphics), out bitmap);
100107
Gdip.CheckStatus(status);
@@ -128,8 +135,10 @@ public Bitmap(Image original, Size newSize) : this(original, newSize.Width, newS
128135
{
129136
}
130137

131-
public Bitmap(Image original!!, int width, int height) : this(width, height, PixelFormat.Format32bppArgb)
138+
public Bitmap(Image original, int width, int height) : this(width, height, PixelFormat.Format32bppArgb)
132139
{
140+
ArgumentNullException.ThrowIfNull(original);
141+
133142
using (Graphics g = Graphics.FromImage(this))
134143
{
135144
g.Clear(Color.Transparent);

src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/GraphicsPath.cs

Lines changed: 84 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public GraphicsPath(FillMode fillMode)
2626

2727
public GraphicsPath(PointF[] pts, byte[] types) : this(pts, types, FillMode.Alternate) { }
2828

29-
public unsafe GraphicsPath(PointF[] pts!!, byte[] types, FillMode fillMode)
29+
public unsafe GraphicsPath(PointF[] pts, byte[] types, FillMode fillMode)
3030
{
31+
ArgumentNullException.ThrowIfNull(pts);
32+
3133
if (pts.Length != types.Length)
3234
throw Gdip.StatusException(Gdip.InvalidParameter);
3335

@@ -43,8 +45,10 @@ public unsafe GraphicsPath(PointF[] pts!!, byte[] types, FillMode fillMode)
4345

4446
public GraphicsPath(Point[] pts, byte[] types) : this(pts, types, FillMode.Alternate) { }
4547

46-
public unsafe GraphicsPath(Point[] pts!!, byte[] types, FillMode fillMode)
48+
public unsafe GraphicsPath(Point[] pts, byte[] types, FillMode fillMode)
4749
{
50+
ArgumentNullException.ThrowIfNull(pts);
51+
4852
if (pts.Length != types.Length)
4953
throw Gdip.StatusException(Gdip.InvalidParameter);
5054

@@ -242,8 +246,10 @@ public bool IsOutlineVisible(float x, float y, Pen pen, Graphics? graphics)
242246
return IsOutlineVisible(new PointF(x, y), pen, graphics);
243247
}
244248

245-
public bool IsOutlineVisible(PointF pt, Pen pen!!, Graphics? graphics)
249+
public bool IsOutlineVisible(PointF pt, Pen pen, Graphics? graphics)
246250
{
251+
ArgumentNullException.ThrowIfNull(pen);
252+
247253
Gdip.CheckStatus(Gdip.GdipIsOutlineVisiblePathPoint(
248254
new HandleRef(this, _nativePath),
249255
pt.X, pt.Y,
@@ -260,8 +266,10 @@ public bool IsOutlineVisible(PointF pt, Pen pen!!, Graphics? graphics)
260266

261267
public bool IsOutlineVisible(int x, int y, Pen pen, Graphics? graphics) => IsOutlineVisible(new Point(x, y), pen, graphics);
262268

263-
public bool IsOutlineVisible(Point pt, Pen pen!!, Graphics? graphics)
269+
public bool IsOutlineVisible(Point pt, Pen pen, Graphics? graphics)
264270
{
271+
ArgumentNullException.ThrowIfNull(pen);
272+
265273
Gdip.CheckStatus(Gdip.GdipIsOutlineVisiblePathPointI(
266274
new HandleRef(this, _nativePath),
267275
pt.X, pt.Y,
@@ -279,8 +287,10 @@ public void AddLine(float x1, float y1, float x2, float y2)
279287
Gdip.CheckStatus(Gdip.GdipAddPathLine(new HandleRef(this, _nativePath), x1, y1, x2, y2));
280288
}
281289

282-
public unsafe void AddLines(PointF[] points!!)
290+
public unsafe void AddLines(PointF[] points)
283291
{
292+
ArgumentNullException.ThrowIfNull(points);
293+
284294
if (points.Length == 0)
285295
throw new ArgumentException(null, nameof(points));
286296

@@ -297,8 +307,10 @@ public void AddLine(int x1, int y1, int x2, int y2)
297307
Gdip.CheckStatus(Gdip.GdipAddPathLineI(new HandleRef(this, _nativePath), x1, y1, x2, y2));
298308
}
299309

300-
public unsafe void AddLines(Point[] points!!)
310+
public unsafe void AddLines(Point[] points)
301311
{
312+
ArgumentNullException.ThrowIfNull(points);
313+
302314
if (points.Length == 0)
303315
throw new ArgumentException(null, nameof(points));
304316

@@ -348,8 +360,10 @@ public void AddBezier(float x1, float y1, float x2, float y2, float x3, float y3
348360
x1, y1, x2, y2, x3, y3, x4, y4));
349361
}
350362

351-
public unsafe void AddBeziers(PointF[] points!!)
363+
public unsafe void AddBeziers(PointF[] points)
352364
{
365+
ArgumentNullException.ThrowIfNull(points);
366+
353367
fixed (PointF* p = points)
354368
{
355369
Gdip.CheckStatus(Gdip.GdipAddPathBeziers(new HandleRef(this, _nativePath), p, points.Length));
@@ -368,8 +382,10 @@ public void AddBezier(int x1, int y1, int x2, int y2, int x3, int y3, int x4, in
368382
x1, y1, x2, y2, x3, y3, x4, y4));
369383
}
370384

371-
public unsafe void AddBeziers(params Point[] points!!)
385+
public unsafe void AddBeziers(params Point[] points)
372386
{
387+
ArgumentNullException.ThrowIfNull(points);
388+
373389
if (points.Length == 0)
374390
return;
375391

@@ -382,16 +398,20 @@ public unsafe void AddBeziers(params Point[] points!!)
382398
/// <summary>
383399
/// Add cardinal splines to the path object
384400
/// </summary>
385-
public unsafe void AddCurve(PointF[] points!!)
401+
public unsafe void AddCurve(PointF[] points)
386402
{
403+
ArgumentNullException.ThrowIfNull(points);
404+
387405
fixed (PointF* p = points)
388406
{
389407
Gdip.CheckStatus(Gdip.GdipAddPathCurve(new HandleRef(this, _nativePath), p, points.Length));
390408
}
391409
}
392410

393-
public unsafe void AddCurve(PointF[] points!!, float tension)
411+
public unsafe void AddCurve(PointF[] points, float tension)
394412
{
413+
ArgumentNullException.ThrowIfNull(points);
414+
395415
if (points.Length == 0)
396416
return;
397417

@@ -401,68 +421,84 @@ public unsafe void AddCurve(PointF[] points!!, float tension)
401421
}
402422
}
403423

404-
public unsafe void AddCurve(PointF[] points!!, int offset, int numberOfSegments, float tension)
424+
public unsafe void AddCurve(PointF[] points, int offset, int numberOfSegments, float tension)
405425
{
426+
ArgumentNullException.ThrowIfNull(points);
427+
406428
fixed (PointF* p = points)
407429
{
408430
Gdip.CheckStatus(Gdip.GdipAddPathCurve3(
409431
new HandleRef(this, _nativePath), p, points.Length, offset, numberOfSegments, tension));
410432
}
411433
}
412434

413-
public unsafe void AddCurve(Point[] points!!)
435+
public unsafe void AddCurve(Point[] points)
414436
{
437+
ArgumentNullException.ThrowIfNull(points);
438+
415439
fixed (Point* p = points)
416440
{
417441
Gdip.CheckStatus(Gdip.GdipAddPathCurveI(new HandleRef(this, _nativePath), p, points.Length));
418442
}
419443
}
420444

421-
public unsafe void AddCurve(Point[] points!!, float tension)
445+
public unsafe void AddCurve(Point[] points, float tension)
422446
{
447+
ArgumentNullException.ThrowIfNull(points);
448+
423449
fixed (Point* p = points)
424450
{
425451
Gdip.CheckStatus(Gdip.GdipAddPathCurve2I(
426452
new HandleRef(this, _nativePath), p, points.Length, tension));
427453
}
428454
}
429455

430-
public unsafe void AddCurve(Point[] points!!, int offset, int numberOfSegments, float tension)
456+
public unsafe void AddCurve(Point[] points, int offset, int numberOfSegments, float tension)
431457
{
458+
ArgumentNullException.ThrowIfNull(points);
459+
432460
fixed (Point* p = points)
433461
{
434462
Gdip.CheckStatus(Gdip.GdipAddPathCurve3I(
435463
new HandleRef(this, _nativePath), p, points.Length, offset, numberOfSegments, tension));
436464
}
437465
}
438466

439-
public unsafe void AddClosedCurve(PointF[] points!!)
467+
public unsafe void AddClosedCurve(PointF[] points)
440468
{
469+
ArgumentNullException.ThrowIfNull(points);
470+
441471
fixed (PointF* p = points)
442472
{
443473
Gdip.CheckStatus(Gdip.GdipAddPathClosedCurve(
444474
new HandleRef(this, _nativePath), p, points.Length));
445475
}
446476
}
447477

448-
public unsafe void AddClosedCurve(PointF[] points!!, float tension)
478+
public unsafe void AddClosedCurve(PointF[] points, float tension)
449479
{
480+
ArgumentNullException.ThrowIfNull(points);
481+
450482
fixed (PointF* p = points)
451483
{
452484
Gdip.CheckStatus(Gdip.GdipAddPathClosedCurve2(new HandleRef(this, _nativePath), p, points.Length, tension));
453485
}
454486
}
455487

456-
public unsafe void AddClosedCurve(Point[] points!!)
488+
public unsafe void AddClosedCurve(Point[] points)
457489
{
490+
ArgumentNullException.ThrowIfNull(points);
491+
458492
fixed (Point* p = points)
459493
{
460494
Gdip.CheckStatus(Gdip.GdipAddPathClosedCurveI(new HandleRef(this, _nativePath), p, points.Length));
461495
}
462496
}
463497

464-
public unsafe void AddClosedCurve(Point[] points!!, float tension)
498+
public unsafe void AddClosedCurve(Point[] points, float tension)
465499
{
500+
ArgumentNullException.ThrowIfNull(points);
501+
466502
fixed (Point* p = points)
467503
{
468504
Gdip.CheckStatus(Gdip.GdipAddPathClosedCurve2I(new HandleRef(this, _nativePath), p, points.Length, tension));
@@ -476,8 +512,10 @@ public void AddRectangle(RectangleF rect)
476512
rect.X, rect.Y, rect.Width, rect.Height));
477513
}
478514

479-
public unsafe void AddRectangles(RectangleF[] rects!!)
515+
public unsafe void AddRectangles(RectangleF[] rects)
480516
{
517+
ArgumentNullException.ThrowIfNull(rects);
518+
481519
if (rects.Length == 0)
482520
throw new ArgumentException(null, nameof(rects));
483521

@@ -495,8 +533,10 @@ public void AddRectangle(Rectangle rect)
495533
rect.X, rect.Y, rect.Width, rect.Height));
496534
}
497535

498-
public unsafe void AddRectangles(Rectangle[] rects!!)
536+
public unsafe void AddRectangles(Rectangle[] rects)
499537
{
538+
ArgumentNullException.ThrowIfNull(rects);
539+
500540
if (rects.Length == 0)
501541
throw new ArgumentException(null, nameof(rects));
502542

@@ -547,8 +587,10 @@ public void AddPie(int x, int y, int width, int height, float startAngle, float
547587
sweepAngle));
548588
}
549589

550-
public unsafe void AddPolygon(PointF[] points!!)
590+
public unsafe void AddPolygon(PointF[] points)
551591
{
592+
ArgumentNullException.ThrowIfNull(points);
593+
552594
fixed (PointF* p = points)
553595
{
554596
Gdip.CheckStatus(Gdip.GdipAddPathPolygon(new HandleRef(this, _nativePath), p, points.Length));
@@ -558,16 +600,20 @@ public unsafe void AddPolygon(PointF[] points!!)
558600
/// <summary>
559601
/// Adds a polygon to the current figure.
560602
/// </summary>
561-
public unsafe void AddPolygon(Point[] points!!)
603+
public unsafe void AddPolygon(Point[] points)
562604
{
605+
ArgumentNullException.ThrowIfNull(points);
606+
563607
fixed (Point* p = points)
564608
{
565609
Gdip.CheckStatus(Gdip.GdipAddPathPolygonI(new HandleRef(this, _nativePath), p, points.Length));
566610
}
567611
}
568612

569-
public void AddPath(GraphicsPath addingPath!!, bool connect)
613+
public void AddPath(GraphicsPath addingPath, bool connect)
570614
{
615+
ArgumentNullException.ThrowIfNull(addingPath);
616+
571617
Gdip.CheckStatus(Gdip.GdipAddPathPath(
572618
new HandleRef(this, _nativePath), new HandleRef(addingPath, addingPath._nativePath), connect));
573619
}
@@ -582,8 +628,10 @@ public void AddString(string s, FontFamily family, int style, float emSize, Poin
582628
AddString(s, family, style, emSize, new Rectangle(origin.X, origin.Y, 0, 0), format);
583629
}
584630

585-
public void AddString(string s, FontFamily family!!, int style, float emSize, RectangleF layoutRect, StringFormat? format)
631+
public void AddString(string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat? format)
586632
{
633+
ArgumentNullException.ThrowIfNull(family);
634+
587635
Gdip.CheckStatus(Gdip.GdipAddPathString(
588636
new HandleRef(this, _nativePath),
589637
s,
@@ -595,8 +643,10 @@ public void AddString(string s, FontFamily family!!, int style, float emSize, Re
595643
new HandleRef(format, format?.nativeFormat ?? IntPtr.Zero)));
596644
}
597645

598-
public void AddString(string s, FontFamily family!!, int style, float emSize, Rectangle layoutRect, StringFormat? format)
646+
public void AddString(string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat? format)
599647
{
648+
ArgumentNullException.ThrowIfNull(family);
649+
600650
Gdip.CheckStatus(Gdip.GdipAddPathStringI(
601651
new HandleRef(this, _nativePath),
602652
s,
@@ -608,8 +658,10 @@ public void AddString(string s, FontFamily family!!, int style, float emSize, Re
608658
new HandleRef(format, format?.nativeFormat ?? IntPtr.Zero)));
609659
}
610660

611-
public void Transform(Matrix matrix!!)
661+
public void Transform(Matrix matrix)
612662
{
663+
ArgumentNullException.ThrowIfNull(matrix);
664+
613665
if (matrix.NativeMatrix == IntPtr.Zero)
614666
return;
615667

@@ -649,8 +701,10 @@ public void Flatten(Matrix? matrix, float flatness)
649701

650702
public void Widen(Pen pen, Matrix? matrix) => Widen(pen, matrix, Flatness);
651703

652-
public void Widen(Pen pen!!, Matrix? matrix, float flatness)
704+
public void Widen(Pen pen, Matrix? matrix, float flatness)
653705
{
706+
ArgumentNullException.ThrowIfNull(pen);
707+
654708
// GDI+ wrongly returns an out of memory status when there is nothing in the path, so we have to check
655709
// before calling the widen method and do nothing if we dont have anything in the path.
656710
if (PointCount == 0)
@@ -672,8 +726,10 @@ public void Warp(PointF[] destPoints, RectangleF srcRect, Matrix? matrix, WarpMo
672726
Warp(destPoints, srcRect, matrix, warpMode, 0.25f);
673727
}
674728

675-
public unsafe void Warp(PointF[] destPoints!!, RectangleF srcRect, Matrix? matrix, WarpMode warpMode, float flatness)
729+
public unsafe void Warp(PointF[] destPoints, RectangleF srcRect, Matrix? matrix, WarpMode warpMode, float flatness)
676730
{
731+
ArgumentNullException.ThrowIfNull(destPoints);
732+
677733
fixed (PointF* p = destPoints)
678734
{
679735
Gdip.CheckStatus(Gdip.GdipWarpPath(

src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/LinearGradientBrush.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,10 @@ public void ResetTransform()
476476

477477
public void MultiplyTransform(Matrix matrix) => MultiplyTransform(matrix, MatrixOrder.Prepend);
478478

479-
public void MultiplyTransform(Matrix matrix!!, MatrixOrder order)
479+
public void MultiplyTransform(Matrix matrix, MatrixOrder order)
480480
{
481+
ArgumentNullException.ThrowIfNull(matrix);
482+
481483
// Multiplying the transform by a disposed matrix is a nop in GDI+, but throws
482484
// with the libgdiplus backend. Simulate a nop for compatability with GDI+.
483485
if (matrix.NativeMatrix == IntPtr.Zero)

0 commit comments

Comments
 (0)