7

Is it possible to assign a System.Diagnostics.DebuggerDisplay attribute to the definition of a Dictionary?

e.g.

Dictionary<int, SomeClass> 
[System.Diagnostics.DebuggerDisplay("{Info,nq}")]
public class SomeClass{

    string code {get;set;}

    public string Info { get { return "info" + code; }}
}


// place an attribute here??
[System.Diagnostics.DebuggerDisplay("{???,nq}")]
Dictionary<int, SomeClass> dict = new Dictionary<int, SomeClass>();
sgtz
  • 8,849
  • 9
  • 51
  • 91

1 Answers1

7

EDIT: see also this answer.

I haven't tried it, but from the documentation, it's possible to apply this attribute at the assembly level. So in theory, you could do something like this:

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

I'd be surprised if it lets you get away with specifying a Target which is an open generic type, e.g. Target = typeof(KeyValuePair<,>) which would work for a KVP of any type. But if you need that, it's worth a try!

Community
  • 1
  • 1
anton.burger
  • 5,637
  • 32
  • 48