DebuggerTypeProxyAttribute Klasa

Definicja

Określa wyświetlany element proxy dla typu.

public ref class DebuggerTypeProxyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple=true)]
public sealed class DebuggerTypeProxyAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple=true)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class DebuggerTypeProxyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple=true)>]
type DebuggerTypeProxyAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple=true)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DebuggerTypeProxyAttribute = class
    inherit Attribute
Public NotInheritable Class DebuggerTypeProxyAttribute
Inherits Attribute
Dziedziczenie
DebuggerTypeProxyAttribute
Atrybuty

Przykłady

Poniższy przykład kodu przedstawia użycie elementu DebuggerTypeProxyAttribute , aby określić prywatny typ zagnieżdżony, który ma być używany jako serwer proxy wyświetlania debugera. Ten przykład kodu jest częścią większego przykładu udostępnionego DebuggerDisplayAttribute dla klasy .

[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

Uwagi

Uwaga Użyj tego atrybutu, jeśli musisz znacząco i zasadniczo zmienić widok debugowania typu, ale nie zmienić samego typu.

Atrybut DebuggerTypeProxyAttribute służy do określania wyświetlanego serwera proxy dla typu, co umożliwia deweloperowi dostosowanie widoku dla typu. Ten atrybut może być również używany na poziomie zestawu, w takim przypadku Target właściwość określa typ, dla którego będzie używany serwer proxy. Ogólnie rzecz biorąc, ten atrybut określa prywatny typ zagnieżdżony, który występuje w obrębie typu, do którego jest stosowany atrybut. Ewaluator wyrażeń obsługujący osoby przeglądające typy sprawdza ten atrybut po wyświetleniu typu. Jeśli atrybut zostanie znaleziony, ewaluator wyrażeń zastępuje typ serwera proxy wyświetlania dla typu atrybut jest stosowany.

DebuggerBrowsableAttribute Gdy element jest obecny, w oknie zmiennej debugera są wyświetlane tylko publiczne elementy członkowskie typu serwera proxy. Prywatne elementy członkowskie nie są wyświetlane. Zachowanie okna danych nie jest zmieniane przez widoki rozszerzone atrybutów.

Aby uniknąć niepotrzebnych kar za wydajność, ewaluatorzy wyrażeń nie powinni sprawdzać atrybutów na wyświetlanym serwerze proxy typu, chyba że typ jest rozwinięty, albo przez użytkownika klikając znak plus (+) obok typu w oknie danych lub za pomocą zastosowania atrybutu DebuggerBrowsableAttribute . W związku z tym zaleca się, aby do typu wyświetlania nie były stosowane żadne atrybuty. Atrybuty mogą i powinny być stosowane w treści typu wyświetlania.

Konstruktory

DebuggerTypeProxyAttribute(String)

Inicjuje DebuggerTypeProxyAttribute nowe wystąpienie klasy przy użyciu nazwy typu serwera proxy.

DebuggerTypeProxyAttribute(Type)

Inicjuje DebuggerTypeProxyAttribute nowe wystąpienie klasy przy użyciu typu serwera proxy.

Właściwości

ProxyTypeName

Pobiera nazwę typu serwera proxy.

Target

Pobiera lub ustawia typ docelowy atrybutu.

TargetTypeName

Pobiera lub ustawia nazwę typu docelowego.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu .

(Odziedziczone po Attribute)

Metody

Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.

(Odziedziczone po Attribute)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Odziedziczone po Attribute)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

Podczas zastępowania w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną dla klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

Po przesłonięciu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, który może służyć do pobierania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też