Wednesday, August 31, 2011

Handy Debugging Attributes

http://msdn.microsoft.com/en-us/library/ms228992.aspx

[DebuggerDisplay("Count = {count}")]
class MyHashtable
{
    public int count = 4;
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public static string y = "Test String";
[DebuggerTypeProxy(typeof(HashtableDebugView))]
class MyHashtable : Hashtable
{
    private const string TestString = 
        "This should not appear in the debug window.";

    internal class HashtableDebugView
    {
        private Hashtable hashtable;
        public const string TestStringProxy = 
            "This should appear in the debug window.";

        // The constructor for the type proxy class must have a 
        // constructor that takes the target type as a parameter.
        public HashtableDebugView(Hashtable hashtable)
        {
            this.hashtable = hashtable;
        }
    }
}

No comments:

Post a Comment