12

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 = new C(); }

public class C { }

Then a new D() will present as {C} in the debugger. Removing the ,nq from the display string has the same effect. Only if I change the type of c to a string, like this

[DebuggerDisplay("{c,nq}")]
public class D { public string c = "foo"; }

does removing/keeping ,nq seem to have effect (it results in "foo" and foo, respectively). So does ,nq only matter when you're trying to display a string field/member?

James Ko
  • 32,215
  • 30
  • 128
  • 239

1 Answers1

24

'nq' literally means 'no quotes' (strip leading quotes from object value). So, yes, only when trying to display string members.

https://blogs.msdn.microsoft.com/jaredpar/2011/03/18/debuggerdisplay-attribute-best-practices/

Eric
  • 1,737
  • 1
  • 13
  • 17