DebuggerTypeProxyAttribute 类

定义

指定类型的显示代理。

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
继承
DebuggerTypeProxyAttribute
属性

示例

下面的代码示例演示如何使用 DebuggerTypeProxyAttribute 指定要用作调试器显示代理的专用嵌套类型。 此代码示例是为类提供的大型示例的 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

注解

注意 如果需要显著和从根本上更改类型的调试视图,但不更改类型本身,请使用此属性。

DebuggerTypeProxyAttribute 属性用于为类型指定显示代理,允许开发人员为类型定制视图。 此属性也可以在程序集级别使用,在这种情况下, Target 该属性指定将为其使用代理的类型。 一般情况下,此属性指定在应用属性的类型内发生的专用嵌套类型。 显示类型时,支持类型查看器的表达式计算器将检查此属性。 如果找到该属性,表达式计算器会将显示代理类型替换为应用该属性的类型。

显示 DebuggerBrowsableAttribute 时,调试器变量窗口仅显示代理类型的公共成员。 不会显示私有成员。 属性增强视图不会改变数据窗口的行为。

为避免不必要的性能损失,表达式计算器不应检查类型显示代理上的属性,除非该类型已展开,要么通过用户单击数据窗口中的类型旁边的加号 (+) ,或者通过属性的应用程序 DebuggerBrowsableAttribute 来检查属性。 因此,建议不要对显示类型应用任何属性。 可以且应该在显示类型的正文中应用属性。

构造函数

DebuggerTypeProxyAttribute(String)

使用代理类型名称初始化 DebuggerTypeProxyAttribute 类的新实例。

DebuggerTypeProxyAttribute(Type)

将使用此类型代理的 DebuggerTypeProxyAttribute 类的新实例初始化。

属性

ProxyTypeName

获取代理类型的类型名称。

Target

获取或设置属性的目标类型。

TargetTypeName

获取或设置目标类型的名称。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅