Switch.GetSupportedAttributes Method

Definition

Gets the custom attributes supported by the switch.

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

Returns

String[]

A string array that contains the names of the custom attributes supported by the switch, or null if there no custom attributes are supported.

Examples

The following code sample shows an override of the GetSupportedAttributes method for a custom switch.

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

Remarks

The default implementation for the GetSupportedAttributes method returns null. If a switch is added in a configuration file and custom attributes are specified that are not included in the string array returned by GetSupportedAttributes, a ConfigurationException is thrown when the switch is loaded.

Notes to Inheritors

When inheriting from the Switch class or a derived class, you can override the GetSupportedAttributes() method to provide custom attributes for your class.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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