属性 [DebuggerDisplay] ( Using DebuggerDisplayAttribute ) 允许在 VS 2010/2008 的调试器中定义显示。通过修改 AutoExp.cs/.dll,我什至可以覆盖系统类型和第 3 方类型的显示,例如
[assembly: DebuggerDisplay (@"\{Name = {Name} FullName = {FullName}}", Target = typeof (Type))]
在内花括号中,我可以引用字段、属性和方法。是否可以引用扩展方法?
例如,我尝试显示较短的类型名称,例如,$SCG.Dictionary
而不是System.Collections.Generic.Dictionary
. 我将此添加到 AutoExp.cs:
using DbgDisp;
[assembly: DebuggerDisplay (@"\{Name = {Name} ShortName = {ShortName()}}", Target = typeof (Type))]
namespace DbgDisp {
public static class Ext {
public static string ShortName (this Type t) { return string.Format ("[{0}]", t.Name); }
} // Ext
} // DbgDisp
但调试器抱怨:当前上下文中不存在名称“ShortName”。
我是否遗漏了一些东西,或者只是不能在那里使用扩展方法?
我知道我可以覆盖ToString ()
,但这仅对我自己的类型有帮助。