2013-11-27 33 views
2

的收集可以說我有一個對象DebuggerDisplay忽略的展示項目

[DebuggerDisplay("Bar={bar}")] 
public class Foo 
{ 
    pubic String bar{get;set;} 
} 

當我有酒吧的單個實例調試程序正確地顯示Bar="value of bar" 但我有Foo本詞典,字典節目時,當

{[key, namespace.Foo]} 

當我展開kvp我得到預期的調試器顯示字符串。

當我覆蓋FooToString()和有Foo 字典詞典顯示

{[key, Bar="value of bar"]} 

根據ToString()僅用於調試器顯示如果DebuggerDisplay屬性不會覆蓋它的文檔...

除了單個實例之外,如何獲得debuggerDisplay屬性來重寫枚舉情況下的調試器字符串?

+1

你不得不創建你自己的'派生類型IDictionary ',並用'DebuggerDisplayAttribute'對其進行賦值 –

回答

0

一個優雅的解決這個問題是通過AssemblyInfo.csDebuggerDisplay 屬性應用到System.Collections.Generic.KeyValuePair<TKey,TValue> 如下:

using System.Collections.Generic; 
using System.Diagnostics; 

[assembly: DebuggerDisplay("[Key={Key}, Value={Value}]", Target = typeof(KeyValuePair<,>))] 

Source on StackoverFlow