BooleanSwitch.Enabled Propiedad

Definición

Obtiene o establece un valor que indica si el modificador está habilitado o deshabilitado.

public:
 property bool Enabled { bool get(); void set(bool value); };
public bool Enabled { get; set; }
member this.Enabled : bool with get, set
Public Property Enabled As Boolean

Valor de propiedad

true si el modificador está habilitado; de lo contrario, false. El valor predeterminado es false.

Excepciones

El autor de la llamada no tiene el permiso correcto.

Ejemplos

En el ejemplo de código siguiente se crea un BooleanSwitch y se usa el modificador para determinar si se debe imprimir un mensaje de error. El modificador se crea en el nivel de clase. El Main método pasa su ubicación a MyMethod, que imprime un mensaje de error y la ubicación donde se produjo el error.

//Class level declaration.
/* Create a BooleanSwitch for data.*/
static BooleanSwitch dataSwitch = new BooleanSwitch("Data", "DataAccess module");

static public void MyMethod(string location)
{
    //Insert code here to handle processing.
    if (dataSwitch.Enabled)
        Console.WriteLine("Error happened at " + location);
}

public static void Main(string[] args)
{
    //Run the method that writes an error message specifying the location of the error.
    MyMethod("in Main");
}
'Class level declaration.
' Create a BooleanSwitch for data. 
Private Shared dataSwitch As New BooleanSwitch("Data", "DataAccess module")


Public Shared Sub MyMethod(location As String)
    'Insert code here to handle processing.
    If dataSwitch.Enabled Then
        Console.WriteLine(("Error happened at " + location))
    End If
End Sub

'Entry point which delegates to C-style main Private Function
Public Overloads Shared Sub Main()
    Main(System.Environment.GetCommandLineArgs())
End Sub
 
Overloads Public Shared Sub Main(args() As String)
    'Run the method that writes an error message specifying the location of the error.
    MyMethod("in Main")
End Sub

Comentarios

De forma predeterminada, este campo se establece false en (deshabilitado). Para habilitar el modificador, asigne a este campo el valor de true. Para deshabilitar el modificador, asigne el valor a false. El valor de esta propiedad viene determinado por el valor de la propiedad SwitchSettingde clase base .

Se aplica a

Consulte también