views:

31

answers:

2

I read about the DebuggerBrowsable attribute yesterday, and it sounded great, however when I tried to get it to work in a test, It doesn't seem to make any difference. I am using VS 2008 version 9.0.30729 1 SP, .Net 3.5 SP1, MSTest framework

    [TestClass]
    public class TestingDebuggerBrowsable
    {
        [TestMethod]
        public void JustToDemonstrateDebugging()
        {
            var foo = new MyExposedClass();
            foo.ToString(); // I put a breakpoint here, and debugged the test
        }

    }

    public class MyExposedClass
    {
        public MyExposedClass()
        {
            ShouldBeSeeingThisInMyDebugger = new List<string> {"foo", "bar"};
        }

        [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
        public IList<string> ShouldBeSeeingThisInMyDebugger { get; set; }
    }

When I hover over foo, I get the usual Representation of List , where I have to drill down a few levels to get to the elements, no different than if I omitted the attribute.

I was hoping to just hover my mouse over the ShouldBeSeeingThisInMyDebugger property, and see the elements of the collection.

EDIT: It seems that this is working on Jeroen's machine, but not mine, despite using the same IDE and framework. I'd be interested to hear if anyone else has the same problem as me.

A: 

According to MSDN it says RootHidden will only hide the root element and expands the child items to show when you hover over it -

here is another link to explain what each attribute does -

http://www.dev102.com/2009/04/09/debuggerdisplay-and-debuggerbrowsable-two-debugger-attributes-you-should-know/

Sachin Shanbhag
+1  A: 

With the attribute added you get:

foo                                               {Sample.MyExposedClass}
    [0]                                           "foo"
    [1]                                           "bar"
  Raw View

Without the attribute you get:

foo                                               {Sample.MyExposedClass}
    ShouldBeSeeingThisInMyDebugger                Count = 2
        [0]                                       "foo"
        [1]                                       "bar"
  Raw View

So with the attribute ShouldBeSeeingThisInMyDebugger is omitted (the root is hidden). Just as the attribute says.

Jeroen
You're decribing what I was hoping to see, but not what I'm getting. Are you using the same version of IDE and framework as me? In my debugger adding the attribute makes NO DIFFERENCE to what I see.
Jonny Cundall
I am running VS 2008, version 9.0.30271.1 SP, Microsoft .NET Framework 3.5 SP 1.
Jeroen
Curious. Well +1 for trying anyway, there must be some mysterious difference to my build setup or something that's stopping it working on my machine
Jonny Cundall