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.DebuggerTypeProxyAttribute
Public 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.DebuggerTypeProxyAttribute
Public Sub New (type As Type)
参数
- type
- Type
代理类型。
例外
type 是 null。
示例
下面的代码示例演示如何使用 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
注解
每次需要显示目标类型的变量时,调试器都会创建类型代理类的新实例。 这可能导致性能影响。 因此,不应在构造函数中执行任何比绝对必要的工作。