Questions tagged [debuggerdisplay]

The DebuggerDisplay attribute can be added to a class, structure or many other elements of your code. The attribute includes a single argument that is supplied as a string. This string is displayed in debugger windows instead of the object's class name or the results of the ToString method.

The DebuggerDisplay attribute can be added to a class, structure or many other elements of your code. The attribute includes a single argument that is supplied as a string. This string is displayed in debugger windows instead of the object's class name or the results of the ToString method. The string can contain references to fields, properties and methods in the class so that the actual values from an object may be included in its description. It may also include simple expressions.

From http://www.blackwasp.co.uk/DebuggerDisplay.aspx

27 questions
100
votes
7 answers

C# debugging: [DebuggerDisplay] or ToString()?

There are two ways to increase the usefulness of debugging information instead of seeing {MyNamespace.MyProject.MyClass} in the debugger. These are the use of DebuggerDisplayAttribute and the ToString() method. using…
bwerks
  • 8,651
  • 14
  • 68
  • 100
30
votes
4 answers

Is it possible to use conditions in a DebuggerDisplay?

Consider the following class: [DebuggerDisplay("{GetType().Name,nq}: FileName = {FileName,nq}")] public class FileWrapper { public string FileName { get; set; } public bool IsTempFile { get; set; } public string TempFileName { get; set;…
Kees C. Bakker
  • 32,294
  • 27
  • 115
  • 203
16
votes
3 answers

Chaining DebuggerDisplay on complex types

I have several classes defining the DebuggerDisplay attribute. I want to know if there is a way to define one DebuggerDisplay attribute based on another one. If I have the following classes: [DebuggerDisplay ("Text = {Text}")] class A { public…
Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
12
votes
1 answer

Does the DebuggerDisplay directive ",nq" only have effect for strings?

I'm writing some code to automatically parse/evaluate DebuggerDisplay strings for unit testing purposes. I'm curious, does the ,nq directive only have effect for strings? I see that if I write [DebuggerDisplay("{c,nq}")] public class D { public C c…
James Ko
  • 32,215
  • 30
  • 128
  • 239
12
votes
3 answers

Possible to accessing child "DebuggerDisplay" attribute of property?

Current state Having two classes: [DebuggerDisplay(@"One = {One}, two = {Two}")] public class A { public int One { get; set; } public B Two { get; set; } } [DebuggerDisplay(@"Three = {Three}")] public class B { public int Three { get;…
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
9
votes
3 answers

Using extension methods in [DebuggerDisplay] Attribute

The Attribute [DebuggerDisplay] (Using DebuggerDisplayAttribute) allows to define the display in the Debugger of VS 2010/2008. By modifying AutoExp.cs/.dll, I can even override the display of system types and 3rd party types, e.g. [assembly:…
8
votes
4 answers

When to use DebuggerDisplayAttribute

What are some best practices around the DebuggerDisplayAttribute? What guides your decisions on when and how to apply the attribute to your code? For example.. Do you find DebuggerDisplayAttribute more useful on some types of objects (i.e. custom…
Scott Wegner
  • 7,263
  • 2
  • 39
  • 55
7
votes
3 answers

Does there exists a method to render an object using DebuggerDisplayAttribute

I have a number of classes that are decorated with DebuggerDisplayAttribute. I want to be able to add trace statements to Unit Tests that will display instances of these classes. Does there exist a method in the .NET Framework that will display an…
Joe
  • 122,218
  • 32
  • 205
  • 338
5
votes
1 answer

Visual Studio: [DebuggerDisplay], shows "not a valid format specifier" when specifying format

If I specify a (date) format on the [DebuggerDisplay], I see a error CS0726: error CS0726: ':d' is not a valid format specifier For example this code: [DebuggerDisplay("{From:d} - {To:d}") public class DateRange { public DateTime From { get;…
Julian
  • 33,915
  • 22
  • 119
  • 174
4
votes
4 answers

DebuggerDisplay attribute does not work as expected

I know that this attribute should work in C# and yet, in my case it does not. I have a class with a lazy property Children. Accessing this property may have a side effect of roundtripping to the server. So, naturally, I do not want this to happen…
mark
  • 59,016
  • 79
  • 296
  • 580
3
votes
2 answers

debuggerdisplay doesn't display field value as expected

public class A { [DebuggerDisplay("{DDBpp1()}")] public byte[] Bpp = new byte[2]; public string DDBpp1() { return "DDBpp"; } public string DDBpp2() { short result; if…
3
votes
1 answer

DebuggerDisplayAttribute method call with parameter

Is it possible to call a method with parameter(s) within the DebuggerDisplay attribute? I did not find helpful information for this problem in the MSDN article Using the DebuggerDisplay Attribute. I try to call the ToString method with a string…
Koopakiller
  • 2,838
  • 3
  • 32
  • 47
3
votes
0 answers

"override" ToString or DEbuggerDisplay of an external library's class

I am developing XNA stuff and using their Matrix structure. When debugging, the value shown for a Matrix is something like: which is not super convenient to read. I would like to have something like: { R:{ 0; 0; 0 } S:{ 1; 1; 1 } T:{ 0; 0; 0 }…
Mr.Pe
  • 719
  • 1
  • 7
  • 19
2
votes
0 answers

Visual studio/Dotnet DebuggerDisplay attribute, does it have more than "nq" switch?

What switches are there to the DebuggerDisplay attribute? I am aware of the nq switch that removes the quotation marks around the output. Are there more?
LosManos
  • 7,195
  • 6
  • 56
  • 107
2
votes
4 answers

Example where [DebuggerDisplay(...)] attribute is useful?

I am looking for a good concrete example where it is clearly desirable to override ToString() with something, but to use a [DebuggerDisplay(...)] custom attribute to display something else in the debugger?
Timwi
  • 65,159
  • 33
  • 165
  • 230
1
2