James Ko
James Ko

Reputation: 34609

Does the DebuggerDisplay directive ",nq" only have effect for strings?

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?

Upvotes: 14

Views: 4153

Answers (1)

Eric
Eric

Reputation: 1847

'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/

Upvotes: 29

Related Questions