BooleanSwitch.Enabled Propriedade

Definição

Recebe ou define um valor que indica se o interruptor está ativado ou desativado.

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 Propriedade

true se o interruptor estiver ativado; caso contrário, false. A predefinição é false.

Exceções

O interlocutor não tem a permissão correta.

Exemplos

O exemplo de código seguinte cria um BooleanSwitch e usa o interruptor para determinar se deve imprimir uma mensagem de erro. A troca é criada ao nível da turma. O Main método passa a sua localização para MyMethod, que imprime uma mensagem de erro e o local onde o erro ocorreu.

//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

Observações

Por defeito, este campo está definido como false (desativado). Para ativar o comutador, atribui a este campo o valor de true. Para desativar o interruptor, atribua o valor a false. O valor desta propriedade é determinado pelo valor da propriedade SwitchSettingda classe base .

Aplica-se a

Ver também