BooleanSwitch Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy BooleanSwitch.

Przeciążenia

BooleanSwitch(String, String)

Inicjuje BooleanSwitch nowe wystąpienie klasy o określonej nazwie wyświetlanej i opisie.

BooleanSwitch(String, String, String)

Inicjuje BooleanSwitch nowe wystąpienie klasy z określoną nazwą wyświetlaną, opisem i wartością przełącznika domyślnego.

BooleanSwitch(String, String)

Źródło:
BooleanSwitch.cs
Źródło:
BooleanSwitch.cs
Źródło:
BooleanSwitch.cs

Inicjuje BooleanSwitch nowe wystąpienie klasy o określonej nazwie wyświetlanej i opisie.

public:
 BooleanSwitch(System::String ^ displayName, System::String ^ description);
public BooleanSwitch (string displayName, string? description);
public BooleanSwitch (string displayName, string description);
new System.Diagnostics.BooleanSwitch : string * string -> System.Diagnostics.BooleanSwitch
Public Sub New (displayName As String, description As String)

Parametry

displayName
String

Nazwa wyświetlana w interfejsie użytkownika.

description
String

Opis przełącznika.

Przykłady

Poniższy przykład tworzy obiekt BooleanSwitch i używa przełącznika w celu określenia, czy wyświetlić komunikat o błędzie. Przełącznik jest tworzony na poziomie klasy. Metoda Main przekazuje jego lokalizację do MyMethodelementu , który wyświetla komunikat o błędzie i miejsce wystąpienia błędu.

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 which 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 which 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 function.
Public Overloads Shared Sub Main()
    Main(System.Environment.GetCommandLineArgs())
End Sub
 
Overloads Public Shared Sub Main(args() As String)
    ' Run the method which writes an error message specifying the location of the error.
    MyMethod("in Main")
End Sub

Uwagi

Podczas tworzenia BooleanSwitchparametru displayName parametr jest używany do znajdowania ustawień przełącznika początkowego dla aplikacji .NET Framework w pliku konfiguracji aplikacji. Jeśli konstruktor nie może znaleźć ustawień początkowych lub dla aplikacji .NET Core i .NET 5+, Enabled właściwość jest ustawiona na false (wyłączone).

Aby ustawić poziom aplikacji BooleanSwitch w aplikacji .NET Framework, zmodyfikuj plik konfiguracji odpowiadający nazwie aplikacji. W tym pliku można dodać przełącznik i ustawić jego wartość, usunąć przełącznik lub wyczyścić wszystkie przełączniki ustawione wcześniej przez aplikację. Plik konfiguracji powinien być sformatowany tak, jak w poniższym przykładzie:

<configuration>  
    <system.diagnostics>  
       <switches>  
          <add name="mySwitch" value="10" />  
          <add name="myNewSwitch" value="20" />  
          <remove name="mySwitch" />  
          <clear/>  
       </switches>  
    </system.diagnostics>  
 </configuration>  

Uwaga

Utworzone przełączniki powinny mieć wartość static.

Zobacz też

Dotyczy

BooleanSwitch(String, String, String)

Źródło:
BooleanSwitch.cs
Źródło:
BooleanSwitch.cs
Źródło:
BooleanSwitch.cs

Inicjuje BooleanSwitch nowe wystąpienie klasy z określoną nazwą wyświetlaną, opisem i wartością przełącznika domyślnego.

public:
 BooleanSwitch(System::String ^ displayName, System::String ^ description, System::String ^ defaultSwitchValue);
public BooleanSwitch (string displayName, string? description, string defaultSwitchValue);
public BooleanSwitch (string displayName, string description, string defaultSwitchValue);
new System.Diagnostics.BooleanSwitch : string * string * string -> System.Diagnostics.BooleanSwitch
Public Sub New (displayName As String, description As String, defaultSwitchValue As String)

Parametry

displayName
String

Nazwa wyświetlana w interfejsie użytkownika.

description
String

Opis przełącznika.

defaultSwitchValue
String

Wartość domyślna przełącznika.

Dotyczy