BooleanSwitch Konstruktory

Definice

Inicializuje novou instanci BooleanSwitch třídy.

Přetížení

BooleanSwitch(String, String)

Inicializuje novou instanci BooleanSwitch třídy se zadaným zobrazovaným názvem a popisem.

BooleanSwitch(String, String, String)

Inicializuje novou instanci BooleanSwitch třídy se zadaným zobrazovaným názvem, popisem a výchozí hodnotou přepínače.

BooleanSwitch(String, String)

Zdroj:
BooleanSwitch.cs
Zdroj:
BooleanSwitch.cs
Zdroj:
BooleanSwitch.cs

Inicializuje novou instanci BooleanSwitch třídy se zadaným zobrazovaným názvem a popisem.

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

Název, který se má zobrazit v uživatelském rozhraní.

description
String

Popis přepínače.

Příklady

Následující příklad vytvoří BooleanSwitch a použije přepínač k určení, zda se má vytisknout chybová zpráva. Přepínač se vytvoří na úrovni třídy. Metoda Main předá své umístění do MyMethod, který zobrazí chybovou zprávu a kde došlo k chybě.

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

Poznámky

Když vytvoříte BooleanSwitch, použije se displayName parametr k vyhledání počátečního nastavení přepínače pro aplikace .NET Framework v konfiguračním souboru aplikace. Pokud konstruktor nemůže najít počáteční nastavení nebo pro aplikace .NET Core a .NET 5 nebo novější, vlastnost je nastavená Enabled na false (zakázáno).

Pokud chcete nastavit úroveň aplikace .NET Framework, upravte BooleanSwitch konfigurační soubor odpovídající názvu vaší aplikace. V tomto souboru můžete přidat přepínač a nastavit jeho hodnotu, odebrat přepínač nebo vymazat všechny přepínače, které aplikace předtím nastavovala. Konfigurační soubor by měl být naformátovaný jako v následujícím příkladu:

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

Poznámka

Vytvořené přepínače by měly být static.

Viz také

Platí pro

BooleanSwitch(String, String, String)

Zdroj:
BooleanSwitch.cs
Zdroj:
BooleanSwitch.cs
Zdroj:
BooleanSwitch.cs

Inicializuje novou instanci BooleanSwitch třídy se zadaným zobrazovaným názvem, popisem a výchozí hodnotou přepínače.

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

Název, který se má zobrazit v uživatelském rozhraní.

description
String

Popis přepínače.

defaultSwitchValue
String

Výchozí hodnota přepínače.

Platí pro