Export (0) Print
Expand All

DebuggerTypeProxyAttribute Class

Note: This class is new in the .NET Framework version 2.0.

Specifies the display proxy for a type.

Namespace: System.Diagnostics
Assembly: mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct, AllowMultiple=true)] 
public sealed class DebuggerTypeProxyAttribute : Attribute
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct, AllowMultiple=true) */ 
public final class DebuggerTypeProxyAttribute extends Attribute
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct, AllowMultiple=true) 
public final class DebuggerTypeProxyAttribute extends Attribute

Note   Use this attribute when you need to significantly and fundamentally change the debugging view of a type, but not change the type itself.

The DebuggerTypeProxyAttribute attribute is used to specify a display proxy for a type, allowing a developer to tailor the view for the type. This attribute can be used at the assembly level as well, in which case the Target property specifies the type for which the proxy will be used. In general, this attribute specifies a private nested type that occurs within the type to which the attribute is applied. An expression evaluator that supports type viewers checks for this attribute when a type is displayed. If the attribute is found, the expression evaluator substitutes the display proxy type for the type the attribute is applied to.

When the DebuggerBrowsableAttribute is present, the debugger variable window displays only the public members of the proxy type. Private members are not displayed. The behavior of the data window is not changed by attribute-enhanced views.

To avoid unnecessary performance penalties, expression evaluators should not examine the attributes on the display proxy of the type unless the type is expanded, either through the user clicking the plus sign (+) next to the type in a data window, or through the application of the DebuggerBrowsableAttribute attribute. Therefore, it is recommended that no attributes be applied to the display type. Attributes can and should be applied within the body of the display type.

The following code example shows the use of the DebuggerTypeProxyAttribute to specify a private nested type to be used as a debugger display proxy. This code example is part of a larger example provided for the DebuggerDisplayAttribute class.

[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 TestString = "This should appear in the debug window.";
      public HashtableDebugView(Hashtable hashtable)
      {
         this.hashtable = hashtable;
      }

      [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
      public KeyValuePairs[] Keys
      {
         get 
         {
             KeyValuePairs[] keys = new KeyValuePairs[hashtable.Count];

            int i = 0;
            foreach(object key in hashtable.Keys)
            {
               keys[i] = new KeyValuePairs(hashtable, key, hashtable[key]);
               i++;
            }
         return keys;
         }
      }
   }
}

System.Object
   System.Attribute
    System.Diagnostics.DebuggerTypeProxyAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft