Created
August 17, 2011 18:33
-
-
Save kumpera/1152262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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