共用方式為


Switch.GetSupportedAttributes 方法

定義

取得由參數支援的自訂屬性。

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 覆寫。

public class MySourceSwitch : SourceSwitch
{
    int sourceAttribute = 0;
    public MySourceSwitch(string n) : base(n) { }
    public int CustomSourceSwitchAttribute
    {
        get
        {
            foreach (DictionaryEntry de in this.Attributes)
                if (de.Key.ToString().ToLower() == "customsourceswitchattribute")
                    sourceAttribute = (int)de.Value;
            return sourceAttribute;
        }
        set { sourceAttribute = (int)value; }
    }

    protected override string[] GetSupportedAttributes()
    {
        return new string[] { "customsourceSwitchattribute" };
    }
}
Public Class MySourceSwitch
    Inherits SourceSwitch
    Private sourceAttribute As Integer = 0

    Public Sub New(ByVal n As String)
        MyBase.New(n)

    End Sub

    Public Property CustomSourceSwitchAttribute() As Integer
        Get
            Dim de As DictionaryEntry
            For Each de In Me.Attributes
                If de.Key.ToString().ToLower() = "customsourceswitchattribute" Then
                    sourceAttribute = Fix(de.Value)
                End If
            Next de
            Return sourceAttribute
        End Get
        Set(ByVal value As Integer)
            sourceAttribute = Fix(Value)
        End Set
    End Property

    Protected Overrides Function GetSupportedAttributes() As String()
        Return New String() {"customsourceSwitchattribute"}

    End Function 'GetSupportedAttributes
End Class

備註

方法預設實作 GetSupportedAttributesnull傳回 。 如果在群組態檔中新增參數,且自訂屬性指定未包含在 所 GetSupportedAttributes傳回的字串陣列中, ConfigurationException 則會在載入參數時擲回 。

給繼承者的注意事項

Switch 類別或衍生類別繼承時,您可以覆寫 GetSupportedAttributes() 方法,以提供類別的自定義屬性。

適用於