BooleanSwitch.Enabled Propriedade

Definição

Obtém ou define um valor que indica se comutador está habilitado ou desabilitado.Gets or sets a value indicating whether the switch is enabled or disabled.

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 da propriedade

Boolean

true se a opção estiver habilitada; caso contrário, false .true if the switch is enabled; otherwise, false. O padrão é false.The default is false.

Exceções

O chamador não tem a permissão correta.The caller does not have the correct permission.

Exemplos

O exemplo de código a seguir cria um BooleanSwitch e usa a opção para determinar se uma mensagem de erro deve ser impressa.The following code example creates a BooleanSwitch and uses the switch to determine whether to print an error message. A opção é criada no nível de classe.The switch is created at the class level. O Main método passa seu local para MyMethod , que imprime uma mensagem de erro e o local em que ocorreu o erro.The Main method passes its location to MyMethod, which prints an error message and the location where the error occurred.

public ref class BooleanSwitchTest
{
private:

   /* Create a BooleanSwitch for data.*/
   static BooleanSwitch^ dataSwitch = gcnew BooleanSwitch( "Data","DataAccess module" );

public:
   static void MyMethod( String^ location )
   {
      
      //Insert code here to handle processing.
      if ( dataSwitch->Enabled )
            Console::WriteLine( "Error happened at {0}", location );
   }

};

int main()
{
   
   //Run the method that writes an error message specifying the location of the error.
   BooleanSwitchTest::MyMethod( "in main" );
}

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

Comentários

Por padrão, esse campo é definido como false (desabilitado).By default, this field is set to false (disabled). Para habilitar a opção, atribua esse campo ao valor de true .To enable the switch, assign this field the value of true. Para desabilitar a opção, atribua o valor a false .To disable the switch, assign the value to false. O valor dessa propriedade é determinado pelo valor da propriedade da classe base SwitchSetting .The value of this property is determined by the value of the base class property SwitchSetting.

Observação

Esse método usa o SecurityAction.LinkDemand sinalizador para evitar ser chamado de código não confiável; somente o chamador imediato precisa ter SecurityPermissionAttribute.UnmanagedCode permissão.This method uses the SecurityAction.LinkDemand flag to prevent being called from untrusted code; only the immediate caller is required to have SecurityPermissionAttribute.UnmanagedCode permission. Se seu código puder ser chamado a partir de código parcialmente confiável, não passe a entrada do usuário para Marshal métodos de classe sem validação.If your code can be called from partially trusted code, do not pass the user input to Marshal class methods without validation.

Aplica-se a

Confira também