TraceSource.GetSupportedAttributes 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取跟踪源所支持的自定义特性。
protected:
virtual cli::array <System::String ^> ^ GetSupportedAttributes();
protected public:
virtual cli::array <System::String ^> ^ GetSupportedAttributes();
protected virtual string[]? GetSupportedAttributes ();
protected virtual string[] GetSupportedAttributes ();
protected internal virtual string[] GetSupportedAttributes ();
abstract member GetSupportedAttributes : unit -> string[]
override this.GetSupportedAttributes : unit -> string[]
Protected Overridable Function GetSupportedAttributes () As String()
Protected Friend Overridable Function GetSupportedAttributes () As String()
返回
String[]
对跟踪源支持的自定义特性进行命名的字符串数组;如果不存在自定义特性,则为 null
。
示例
下面的代码示例演示方法的重写, GetSupportedAttributes 以标识 类的 MyTraceSource
自定义属性。
public class MyTraceSource : TraceSource
{
string firstAttribute = "";
string secondAttribute = "";
public MyTraceSource(string n) : base(n) {}
public string FirstTraceSourceAttribute
{
get {
foreach (DictionaryEntry de in this.Attributes)
if (de.Key.ToString().ToLower() == "firsttracesourceattribute")
firstAttribute = de.Value.ToString() ;
return firstAttribute;
}
set { firstAttribute = value; }
}
public string SecondTraceSourceAttribute
{
get {
foreach (DictionaryEntry de in this.Attributes)
if (de.Key.ToString().ToLower() == "secondtracesourceattribute")
secondAttribute = de.Value.ToString();
return secondAttribute; }
set { secondAttribute = value; }
}
protected override string[] GetSupportedAttributes()
{
// Allow the use of the attributes in the configuration file.
return new string[] { "FirstTraceSourceAttribute", "SecondTraceSourceAttribute" };
}
}
Public Class MyTraceSource
Inherits TraceSource
Private firstAttribute As String = ""
Private secondAttribute As String = ""
Public Sub New(ByVal n As String)
MyBase.New(n)
End Sub
Public Property FirstTraceSourceAttribute() As String
Get
Dim de As DictionaryEntry
For Each de In Me.Attributes
If de.Key.ToString().ToLower() = "firsttracesourceattribute" Then
firstAttribute = de.Value.ToString()
End If
Next de
Return firstAttribute
End Get
Set(ByVal value As String)
firstAttribute = value
End Set
End Property
Public Property SecondTraceSourceAttribute() As String
Get
Dim de As DictionaryEntry
For Each de In Me.Attributes
If de.Key.ToString().ToLower() = "secondtracesourceattribute" Then
secondAttribute = de.Value.ToString()
End If
Next de
Return secondAttribute
End Get
Set(ByVal value As String)
secondAttribute = Value
End Set
End Property
Protected Overrides Function GetSupportedAttributes() As String()
' Allow the use of the attributes in the configuration file.
Return New String() {"FirstTraceSourceAttribute", "SecondTraceSourceAttribute"}
End Function 'GetSupportedAttributes
End Class
注解
的默认实现 GetSupportedAttributes 返回 null
。
继承者说明
从 TraceSource 类或派生类继承时,可以重写 GetSupportedAttributes() 方法,为类提供自定义属性。