System.Drawing.Graphics.DrawImage(Image image, int x, int y) WTF???

I just saw this over on thedailwtf.com:

public void DrawImage(Image image, int x, int y);

Declaring Type: System.Drawing.Graphics
Assembly: System.Drawing, Version=1.0.5000.0

public void DrawImage(Image image, int x, int y)
{
if (this == null)
{
throw new ArgumentNullException("this");
}

if (image == null)
{
throw new ArgumentNullException("image");
}
int num1 = SafeNativeMethods.GdipDrawImageI(new HandleRef(this, this.nativeGraphics), new HandleRef(image, image.nativeImage), x, y);
this.CheckErrorStatus(num1);
}


I verified this with Lutz Roder's reflector. I see that those programmers over at MS are mortals just like the rest of us. :-)
Published Friday, September 30, 2005 8:31 PM by findleyd

Comments

# re: System.Drawing.Graphics.DrawImage(Image image, int x, int y) WTF???

Friday, September 30, 2005 10:13 PM by Wesner Moise
When System.Drawing was written, C# allowed null this pointers... It was later that ECMA disallowed C# from allowing instance methods to be called on null pointers.

# re: System.Drawing.Graphics.DrawImage(Image image, int x, int y) WTF???

Saturday, October 01, 2005 6:20 PM by David Findley
How could you have even called an instance method with a null this pointer? I'm assuming this must have been a managed<->unmanaged code scenario.

# re: System.Drawing.Graphics.DrawImage(Image image, int x, int y) WTF???

Monday, October 03, 2005 4:40 AM by Avner Kashtan
I'm guessing here, but would invoking a method through reflection and passing null as the instance cause this check to be necessary, at least as long as there's no ECMA-compliancy test that disallows this even earlier.

# re: System.Drawing.Graphics.DrawImage(Image image, int x, int y) WTF???

Tuesday, October 04, 2005 4:41 AM by Wesner Moise
Prior to VS.NET Beta 2, you could call

Graphics g = null;
g.DrawImage(...);

In fact, the ability to call non-virtual methods on a null pointer was mentioned as a feature in Eric Gunnerson's first book on C#.

However, ECMA vetoed this feature when Microsoft submitted it for standardization.

Leave a Comment

(required) 
(required) 
(optional)
(required)