2

Lets say I have an object:

[DebuggerDisplay("Bar={bar}")]
public class Foo
{
    public String bar{get;set;}
}

When I have a single instance of bar the debugger correctly shows Bar="value of bar" but when I have a dictionary of Foos, the dictionary shows:

{[key, namespace.Foo]}

when I expand the kvp I get the expected debugger display string.

When I override ToString() in Foo and have a dictionary of Foo the dictionary shows:

{[key, Bar="value of bar"]}

According to the documentation, ToString() is only used for debugger display if a DebuggerDisplay Attribute doesn't override it...

How do I get the debuggerDisplay attribute to override the debugger string in enumerated situations in addition to single instances?

Patrick
  • 1,717
  • 7
  • 21
  • 28
Paragon
  • 127
  • 10

1 Answers1

1

An elegant solution to this problem is to apply the DebuggerDisplay attribute to System.Collections.Generic.KeyValuePair<TKey,TValue> via AssemblyInfo.cs as follows:

using System.Collections.Generic;
using System.Diagnostics;

[assembly: DebuggerDisplay("[Key={Key}, Value={Value}]", Target = typeof(KeyValuePair<,>))]

(Source on StackoverFlow)

hansfbaier
  • 611
  • 5
  • 13