Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 452
James Ko Avatar asked Jan 24 '17 20:01

James Ko


1 Answers

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

like image 139
Eric Avatar answered Nov 09 '22 06:11

Eric