views:

69

answers:

2

I want to apply the DebuggerDisplayAttribute to include an memory address value. Is there a way to have it displayed in hexadecimal?

[DebuggerDisplay("Foo: Address value is {Address}")] 
class Foo 
{
    System.IntPtr m_Address = new System.IntPtr(43981); // Sample value


    System.IntPtr Address
    {
         get { return m_Address; }
    }
}

This will display: Foo: Address value is 43981 Instead, I'd like the value to be displayed in hex, like that: Foo: Address value is 0xABCD.

I know that I could apply all kinds of formatting by overriding ToString(), but I'm curious if the same is possible with DebuggerDisplayAttributes.

Thanks in advance!

+5  A: 

Yes you can use any method off the properties just as you would normally. [DebuggerDisplay("Foo: Address value is {Address.ToString(\"<formatting>\"}")] is an example

http://msdn.microsoft.com/en-us/library/x810d419.aspx

David
+2  A: 

If you only want to view values in hex format, there is an option in Visual Studio to display values in that format. While debugging, hover over your variable to bring up the debugging display, or find a variable in your watch or locals window. Right-click on the variable and select the "Hexadecimal Display" option. The debugger will then display all numeric values in hexadecimal format. In this case, you will get: "Foo: Address value is 0x0000abcd"

Unfortunately I couldn't see any way to really control the format of the string that is displayed by the DebuggerDisplay attribute as you were asking.

Dr. Wily's Apprentice