DebuggerTypeProxyAttribute 建構函式

定義

使用代理的型別初始化該類別的新實例 DebuggerTypeProxyAttribute

多載

名稱 Description
DebuggerTypeProxyAttribute(String)

使用代理的型別名稱初始化該 DebuggerTypeProxyAttribute 類別的新實例。

DebuggerTypeProxyAttribute(Type)

使用代理的型別初始化該類別的新實例 DebuggerTypeProxyAttribute

DebuggerTypeProxyAttribute(String)

來源:
DebuggerTypeProxyAttribute.cs
來源:
DebuggerTypeProxyAttribute.cs
來源:
DebuggerTypeProxyAttribute.cs
來源:
DebuggerTypeProxyAttribute.cs
來源:
DebuggerTypeProxyAttribute.cs

使用代理的型別名稱初始化該 DebuggerTypeProxyAttribute 類別的新實例。

public:
 DebuggerTypeProxyAttribute(System::String ^ typeName);
public DebuggerTypeProxyAttribute(string typeName);
new System.Diagnostics.DebuggerTypeProxyAttribute : string -> System.Diagnostics.DebuggerTypeProxyAttribute
Public Sub New (typeName As String)

參數

typeName
String

代理類型的類型名稱。

備註

偵錯工具會在每次需要顯示目標類型的變數時,都會建立類型 Proxy 類別的新實例。 這可能會對效能產生影響。 因此,你在建構器中不應做超過絕對必要的工作。

適用於

DebuggerTypeProxyAttribute(Type)

來源:
DebuggerTypeProxyAttribute.cs
來源:
DebuggerTypeProxyAttribute.cs
來源:
DebuggerTypeProxyAttribute.cs
來源:
DebuggerTypeProxyAttribute.cs
來源:
DebuggerTypeProxyAttribute.cs

使用代理的型別初始化該類別的新實例 DebuggerTypeProxyAttribute

public:
 DebuggerTypeProxyAttribute(Type ^ type);
public DebuggerTypeProxyAttribute(Type type);
new System.Diagnostics.DebuggerTypeProxyAttribute : Type -> System.Diagnostics.DebuggerTypeProxyAttribute
Public Sub New (type As Type)

參數

type
Type

代理類型。

例外狀況

typenull

範例

以下程式碼範例展示了使用 DebuggerTypeProxyAttribute(Type) 建構子來指定除錯器顯示代理的做法。 此程式碼範例是本類別更大範例 DebuggerDisplayAttribute 的一部分。

[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

備註

偵錯工具會在每次需要顯示目標類型的變數時,都會建立類型 Proxy 類別的新實例。 這可能會對效能產生影響。 因此,你在建構器中不應做超過絕對必要的工作。

適用於