|
1 | 1 | --- |
2 | 2 | title: Display custom info using DebuggerDisplay |
3 | 3 | description: Use an instance of DebuggerDisplayAttribute to control how an object, property, or field is displayed in the debugger variable windows. |
4 | | -ms.date: 04/22/2022 |
| 4 | +ms.date: 04/15/2025 |
5 | 5 | ms.topic: how-to |
6 | 6 | helpviewer_keywords: |
7 | 7 | - attributes, debugger |
@@ -42,18 +42,19 @@ The following table shows some possible uses of the `DebuggerDisplay` attribute |
42 | 42 | |`Name`, `Type`|These parameters affect the **Name** and **Type** columns of the variable windows. (They can be set to strings using the same syntax as the constructor.) Overusing these parameters, or using them incorrectly, can cause confusing output.| |
43 | 43 | |`Target`, `TargetTypeName`|Specifies the target type when the attribute is used at the assembly level.| |
44 | 44 |
|
45 | | -The autoexp.cs file uses the DebuggerDisplay attribute at the assembly level. The autoexp.cs file determines the default expansions that Visual Studio uses for .NET objects. You can examine the autoexp.cs file for examples of how to use the DebuggerDisplay attribute, or you can modify and compile the autoexp.cs file to change the default expansions. Be sure to back up the autoexp.cs file before you modify it. |
| 45 | +The *autoexp.cs* file uses the DebuggerDisplay attribute at the assembly level. The *autoexp.cs* file determines the default expansions that Visual Studio uses for .NET objects. You can examine the *autoexp.cs* file for examples of how to use the DebuggerDisplay attribute, or you can modify and compile the autoexp.cs file to change the default expansions. Be sure to back up the *autoexp.cs* file before you modify it. |
46 | 46 |
|
47 | | -To build autoexp.cs, open up a Developer Command Prompt for VS2015, and run the following commands |
| 47 | +To build *autoexp.cs*, open up a Developer Command Prompt for VS2015, and run the following commands |
48 | 48 |
|
49 | 49 | ```cmd |
50 | 50 | cd <directory containing autoexp.cs> |
51 | 51 | csc /t:library autoexp.cs |
52 | 52 | ``` |
53 | 53 |
|
54 | | -The changes to autoexp.dll will be picked up in the next debug session. |
| 54 | +The changes to *autoexp.dll* will be picked up in the next debug session. |
55 | 55 |
|
56 | 56 | ## Using Expressions in DebuggerDisplay |
| 57 | + |
57 | 58 | Although you can use a general expression between the braces in a DebuggerDisplay attribute, this practice is not recommended. |
58 | 59 |
|
59 | 60 | A general expression in DebuggerDisplay has implicit access to the `this` pointer for the current instance of the target type only. The expression has no access to aliases, locals, or pointers. If the expression references properties, attributes on those properties are not processed. For example, the C# code `[DebuggerDisplay("Object {count - 2}")]` would display `Object 6` if the field `count` was 8. |
@@ -84,9 +85,10 @@ public sealed class MyClass |
84 | 85 | } |
85 | 86 | ``` |
86 | 87 |
|
87 | | -The ",nq" suffix tells the expression evaluator to remove the quotes when displaying the final value (nq = no quotes). |
| 88 | +The ",nq" suffix tells the expression evaluator to remove the quotes when displaying the final value (nq = no quotes). For more information on formatters, see [Format specifiers in C#](../debugger/format-specifiers-in-csharp.md). |
88 | 89 |
|
89 | 90 | ## Example |
| 91 | + |
90 | 92 | The following code example shows how to use `DebuggerDisplay`, together with `DebuggerBrowsable` and `DebuggerTypeProxy`. When viewed in a debugger variables window, such as the **Watch** window, it produces an expansion that looks like this: |
91 | 93 |
|
92 | 94 | |**Name**|**Value**|**Type**| |
|
0 commit comments