Skip to content

Update using-the-debuggerdisplay-attribute.md #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/debugger/using-the-debuggerdisplay-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ csc /t:library autoexp.cs
## Using Expressions in DebuggerDisplay
Although you can use a general expression between the braces in a DebuggerDisplay attribute, this practice is not recommended.

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.
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.

Using expressions in DebuggerDisplay can lead to the following issues:

Expand All @@ -100,7 +100,7 @@ public sealed class MyClass
{       
get
{
return string.Format("("Object {0}", count - 2);
return string.Format("Object {0}", count - 2);
}   
}
}
Expand Down Expand Up @@ -160,7 +160,9 @@ class MyHashtable
public MyHashtable()
{
hashtable = new Hashtable();
} private string DebuggerDisplay { get { return "Count = " + hashtable.Count); } }
}

private string DebuggerDisplay { get { return "Count = " + hashtable.Count); } }

private class HashtableDebugView
{
Expand Down Expand Up @@ -194,4 +196,4 @@ class MyHashtable
[Using DebuggerTypeProxy Attribute](../debugger/using-debuggertypeproxy-attribute.md)
[Create custom views of managed objects](../debugger/create-custom-views-of-dot-managed-objects.md)
[Format specifiers in C#](../debugger/format-specifiers-in-csharp.md)
[Enhancing Debugging with the Debugger Display Attributes](/dotnet/framework/debug-trace-profile/enhancing-debugging-with-the-debugger-display-attributes)
[Enhancing Debugging with the Debugger Display Attributes](/dotnet/framework/debug-trace-profile/enhancing-debugging-with-the-debugger-display-attributes)