DebuggerDisplay 指令是否“,nq"只对字符串有效? [英] Does the DebuggerDisplay directive ",nq" only have effect for strings?
问题描述
我正在编写一些代码来自动解析/评估 DebuggerDisplay
字符串以进行单元测试.我很好奇,,nq
指令是否只对字符串有效?我看到如果我写
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 { }
然后一个 new D()
将在调试器中显示为 {C}
.从显示字符串中删除 ,nq
具有相同的效果.仅当我将 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"; }
删除/保留 ,nq
似乎有效果(它分别导致 "foo"
和 foo
).那么 ,nq
仅在您尝试显示字符串字段/成员时才重要吗?
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?
推荐答案
'nq' 字面意思是无引号"(从对象值中去除前导引号).所以,是的,仅当尝试显示字符串成员时.
'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/
这篇关于DebuggerDisplay 指令是否“,nq"只对字符串有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!