Skip to content

Instantly share code, notes, and snippets.

@kumpera
Created August 17, 2011 18:33
Show Gist options
  • Save kumpera/1152262 to your computer and use it in GitHub Desktop.
Save kumpera/1152262 to your computer and use it in GitHub Desktop.
[StructLayout(LayoutKind.Explicit)]
internal struct ObjectWrapper {
[FieldOffset(0)] object obj;
[FieldOffset(0)] IntPtr handle;
internal static IntPtr Convert (object obj) {
ObjectWrapper wrapper = new ObjectWrapper ();
wrapper.obj = obj;
return wrapper.handle;
}
}
static class Nasty {
public static void NastyDump (this object self)
{
IntPtr nasty = ObjectWrapper.Convert (self);
unsafe {
int *p = (int*)nasty;
int size = 4;
string str = "";
for (int i = 0; i < size; ++i)
str += p [i].ToString("X") + " ";
Log.Debug ("NastyDump", "object {0:X} is {1}", (int)nasty, str);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment