Condividi tramite


DebuggerTypeProxyAttribute Classe

Definizione

Specifica il proxy di visualizzazione per un tipo.

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
Ereditarietà
DebuggerTypeProxyAttribute
Attributi

Esempio

Nell'esempio di codice seguente viene illustrato l'uso di DebuggerTypeProxyAttribute per specificare un tipo annidato privato da usare come proxy di visualizzazione del debugger. Questo esempio di codice fa parte di un esempio più ampio fornito per la DebuggerDisplayAttribute classe .

[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

Commenti

Nota Usare questo attributo quando è necessario modificare significativamente e fondamentalmente la visualizzazione di debug di un tipo, ma non modificare il tipo stesso.

L'attributo DebuggerTypeProxyAttribute viene usato per specificare un proxy di visualizzazione per un tipo, consentendo a uno sviluppatore di personalizzare la visualizzazione per il tipo. Questo attributo può essere usato anche a livello di assembly, nel qual caso la Target proprietà specifica il tipo per il quale verrà usato il proxy. In generale, questo attributo specifica un tipo annidato privato che si verifica all'interno del tipo a cui viene applicato l'attributo. Analizzatore di espressioni che supporta visualizzatori di tipi controlla la presenza di questo attributo quando viene visualizzato un tipo. Se l'attributo viene trovato, l'analizzatore di espressioni sostituisce il tipo proxy di visualizzazione per il tipo a cui viene applicato l'attributo.

DebuggerBrowsableAttribute Quando è presente, la finestra della variabile del debugger visualizza solo i membri pubblici del tipo proxy. I membri privati non vengono visualizzati. Il comportamento della finestra dei dati non viene modificato dalle visualizzazioni arricchite dagli attributi.

Per evitare inutili sanzioni per le prestazioni, gli analizzatori di espressioni non devono esaminare gli attributi nel proxy di visualizzazione del tipo, a meno che il tipo non venga espanso, tramite l'utente che fa clic sul segno più (+) accanto al tipo in una finestra dati o tramite l'applicazione dell'attributo DebuggerBrowsableAttribute . Pertanto, è consigliabile non applicare attributi al tipo di visualizzazione. Gli attributi possono e devono essere applicati all'interno del corpo del tipo di visualizzazione.

Costruttori

Nome Descrizione
DebuggerTypeProxyAttribute(String)

Inizializza una nuova istanza della DebuggerTypeProxyAttribute classe utilizzando il nome del tipo del proxy.

DebuggerTypeProxyAttribute(Type)

Inizializza una nuova istanza della DebuggerTypeProxyAttribute classe utilizzando il tipo del proxy.

Proprietà

Nome Descrizione
ProxyTypeName

Ottiene il nome del tipo di proxy.

Target

Ottiene o imposta il tipo di destinazione per l'attributo .

TargetTypeName

Ottiene o imposta il nome del tipo di destinazione.

TypeId

Se implementato in una classe derivata, ottiene un identificatore univoco per questo Attribute.

(Ereditato da Attribute)

Metodi

Nome Descrizione
Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
GetHashCode()

Restituisce il codice hash per questa istanza.

(Ereditato da Attribute)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

Quando sottoposto a override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
Match(Object)

Quando sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

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

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto .

(Ereditato da Attribute)

Si applica a

Vedi anche