DebuggerTypeProxyAttribute 构造函数   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将使用此类型代理的 DebuggerTypeProxyAttribute 类的新实例初始化。
重载
| DebuggerTypeProxyAttribute(String) | 使用代理类型名称初始化 DebuggerTypeProxyAttribute 类的新实例。 | 
| DebuggerTypeProxyAttribute(Type) | 将使用此类型代理的 DebuggerTypeProxyAttribute 类的新实例初始化。 | 
DebuggerTypeProxyAttribute(String)
使用代理类型名称初始化 DebuggerTypeProxyAttribute 类的新实例。
public:
 DebuggerTypeProxyAttribute(System::String ^ typeName);public DebuggerTypeProxyAttribute (string typeName);new System.Diagnostics.DebuggerTypeProxyAttribute : string -> System.Diagnostics.DebuggerTypeProxyAttributePublic Sub New (typeName As String)参数
- typeName
- String
代理类型的类型名称。
注解
在每次需要显示目标类型的变量时,调试器都会创建类型代理类的一个新实例。 这会对性能产生一定影响。 因此,不应在构造函数中执行非必需的工作。
适用于
DebuggerTypeProxyAttribute(Type)
将使用此类型代理的 DebuggerTypeProxyAttribute 类的新实例初始化。
public:
 DebuggerTypeProxyAttribute(Type ^ type);public DebuggerTypeProxyAttribute (Type type);new System.Diagnostics.DebuggerTypeProxyAttribute : Type -> System.Diagnostics.DebuggerTypeProxyAttributePublic Sub New (type As Type)参数
- type
- Type
代理类型。
例外
              type 为 null。
示例
下面的代码示例演示如何使用 DebuggerTypeProxyAttribute(Type) 构造函数来指定调试器显示代理。 此代码示例是为 DebuggerDisplayAttribute 类提供的一个更大示例的一部分。
[DebuggerTypeProxy(HashtableDebugView::typeid)]
ref class MyHashtable : Hashtable
{
private:
    static const String^ TestString = "This should not appear in the debug window.";
internal:
    ref class HashtableDebugView
    {
    private:
        Hashtable^ hashtable;
    public:
        static const String^ TestString = "This should appear in the debug window.";
        HashtableDebugView(Hashtable^ hashtable)
        {
            this->hashtable = hashtable;
        }
        [DebuggerBrowsable(DebuggerBrowsableState::RootHidden)]
        property array<KeyValuePairs^>^ Keys
        {
            array<KeyValuePairs^>^ get()
            {
                array<KeyValuePairs^>^ keys = gcnew array<KeyValuePairs^>(hashtable->Count);
                IEnumerator^ ie = hashtable->Keys->GetEnumerator();
                int i = 0;
                Object^ key;
                while (ie->MoveNext())
                {
                    key = ie->Current;
                    keys[i] = gcnew KeyValuePairs(hashtable, key, hashtable[key]);
                    i++;
                }
                return keys;
            }
        }
    };
};
[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;
            }
        }
    }
}
<DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(GetType(MyHashtable.HashtableDebugView))> _
Class MyHashtable
    Inherits Hashtable
    Private Const TestString As String = "This should not appear in the debug window."
    Friend Class HashtableDebugView
        Private hashtable As Hashtable
        Public Shared TestString As String = "This should appear in the debug window."
        Public Sub New(ByVal hashtable As Hashtable)
            Me.hashtable = hashtable
        End Sub
        <DebuggerBrowsable(DebuggerBrowsableState.RootHidden)> _
        ReadOnly Property Keys as KeyValuePairs()
            Get
                Dim nkeys(hashtable.Count) as KeyValuePairs
                Dim i as Integer = 0
                For Each key As Object In hashtable.Keys
                    nkeys(i) = New KeyValuePairs(hashtable, key, hashtable(key))
                    i = i + 1
                Next
                Return nkeys
            End Get
        End Property
    End Class
End Class
注解
在每次需要显示目标类型的变量时,调试器都会创建类型代理类的一个新实例。 这会对性能产生一定影响。 因此,不应在构造函数中执行非必需的工作。