Switch.GetSupportedAttributes Metodo

Definizione

Ottiene gli attributi personalizzati supportati dall'opzione.

C#
protected virtual string[]? GetSupportedAttributes ();
C#
protected virtual string[] GetSupportedAttributes ();
C#
protected internal virtual string[] GetSupportedAttributes ();

Restituisce

String[]

Una matrice di stringhe che contiene i nomi degli attributi personalizzati supportati dall'opzione oppure null se non è supportato alcun attributo personalizzato.

Esempio

Nell'esempio di codice seguente viene illustrato un override del GetSupportedAttributes metodo per un'opzione personalizzata.

C#
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" };
    }
}

Commenti

L'implementazione predefinita per il GetSupportedAttributes metodo restituisce null. Se un'opzione viene aggiunta in un file di configurazione e gli attributi personalizzati vengono specificati che non sono inclusi nella matrice di stringhe restituita da GetSupportedAttributes, viene generata un'eccezione ConfigurationException quando viene caricata l'opzione.

Note per gli eredi

Quando ereditano dalla Switch classe o da una classe derivata, è possibile eseguire l'override del GetSupportedAttributes() metodo per fornire attributi personalizzati per la classe.

Si applica a

Prodotto Versioni
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1