问题
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.
回答1:
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.
回答2:
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/
来源:https://stackoverflow.com/questions/3683571/how-do-i-get-debuggerbrowsable-roothidden-to-work