What are the challenges you face when working across database platforms? Take the survey
Options

Incorrect disassembly with unsafe code (pointers)

RickBrewsterRickBrewster Posts: 3
I have some simple methods that follow a pattern like this:

(original C# code)
using RectDouble = PaintDotNet.Rendering.RectDouble;
using Rect = System.Windows.Rect;
public static unsafe RectDouble FromRect(Rect rect)
{
    return *((RectDouble*)&rect);
}

And they show up like this in .NET Reflector:
public static unsafe RectDouble FromRect(Rect rect)
{
    return (RectDouble) ((IntPtr) &rect);
}

This C# code doesn't even work -- it's definitely not some kind of syntactic-sugary equivalent :)

Here's the IL that Reflector shows me too:
.method public hidebysig static valuetype [PaintDotNet.Base]PaintDotNet.Rendering.RectDouble FromRect(valuetype [WindowsBase]System.Windows.Rect rect) cil managed
{
    .maxstack 8
    L_0000: ldarga.s rect
    L_0002: conv.u
    L_0003: ldobj [PaintDotNet.Base]PaintDotNet.Rendering.RectDouble
    L_0008: ret
}

Both Rect and RectDouble are structs with the same layout of { double x; double y; double width; double height; }. You can see RectDouble by disassabling PaintDotNet.Base.dll in the latest release of Paint.NET.

Comments

Sign In or Register to comment.