BooleanSwitch.Enabled Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy przełącznik jest włączony, czy wyłączony.

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

Wartość właściwości

true jeśli przełącznik jest włączony; w przeciwnym razie , false. Wartość domyślna to false.

Wyjątki

Obiekt wywołujący nie ma odpowiednich uprawnień.

Przykłady

Poniższy przykład kodu tworzy przełącznik BooleanSwitch i używa przełącznika, aby określić, czy wyświetlić komunikat o błędzie. Przełącznik jest tworzony na poziomie klasy. Metoda Main przekazuje jego lokalizację do MyMethod, która wyświetla komunikat o błędzie i lokalizację, w której wystąpił błąd.

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

Uwagi

Domyślnie to pole jest ustawione na false (wyłączone). Aby włączyć przełącznik, przypisz to pole jako wartość true. Aby wyłączyć przełącznik, przypisz wartość do false. Wartość tej właściwości jest określana przez wartość właściwości SwitchSettingklasy bazowej .

Dotyczy

Zobacz też