Switch.GetSupportedAttributes Método

Definición

Obtiene los atributos personalizados que admite el modificador.Gets the custom attributes supported by the switch.

protected public:
 virtual cli::array <System::String ^> ^ GetSupportedAttributes();
protected internal virtual string[] GetSupportedAttributes ();
abstract member GetSupportedAttributes : unit -> string[]
override this.GetSupportedAttributes : unit -> string[]
Protected Friend Overridable Function GetSupportedAttributes () As String()

Devoluciones

String[]

Una matriz de cadena que contiene los nombres de los atributos personalizados que admite el modificador, o bien, null si no admite ningún atributo personalizado.A string array that contains the names of the custom attributes supported by the switch, or null if there no custom attributes are supported.

Ejemplos

En el ejemplo de código siguiente se muestra una invalidación del método GetSupportedAttributes para un modificador personalizado.The following code sample shows an override of the GetSupportedAttributes method for a custom switch.

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

Comentarios

La implementación predeterminada del método GetSupportedAttributes devuelve null.The default implementation for the GetSupportedAttributes method returns null. Si se agrega un modificador en un archivo de configuración y se especifican atributos personalizados que no están incluidos en la matriz de cadenas devuelta por GetSupportedAttributes, se produce una ConfigurationException cuando se carga el modificador.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.

Notas a los desarrolladores de herederos

Al heredar de la clase Switch o de una clase derivada, puede invalidar el método GetSupportedAttributes() para proporcionar atributos personalizados a la clase.When inheriting from the Switch class or a derived class, you can override the GetSupportedAttributes() method to provide custom attributes for your class.

Se aplica a