BooleanSwitch Constructors

Definition

Initializes a new instance of the BooleanSwitch class.

Overloads

BooleanSwitch(String, String)

Initializes a new instance of the BooleanSwitch class with the specified display name and description.

BooleanSwitch(String, String, String)

Initializes a new instance of the BooleanSwitch class with the specified display name, description, and default switch value.

BooleanSwitch(String, String)

Source:
BooleanSwitch.cs
Source:
BooleanSwitch.cs
Source:
BooleanSwitch.cs

Initializes a new instance of the BooleanSwitch class with the specified display name and description.

public BooleanSwitch (string displayName, string? description);
public BooleanSwitch (string displayName, string description);

Parameters

displayName
String

The name to display on a user interface.

description
String

The description of the switch.

Examples

The following example creates a BooleanSwitch and uses the switch to determine whether to print an error message. The switch is created at the class level. The Main method passes its location to MyMethod, which prints an error message and where the error occurred.

// 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");
}

Remarks

When you create a BooleanSwitch, the displayName parameter is used to find the initial switch settings for .NET Framework apps in the application configuration file. If the constructor cannot find initial settings, or for .NET Core and .NET 5+ apps, the Enabled property is set to false (disabled).

To set the level of your BooleanSwitch in a .NET Framework app, edit the configuration file corresponding to the name of your application. Within this file, you can add a switch and set its value, remove a switch, or clear all switches previously set by the application. The configuration file should be formatted like the following example:

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

Märkus

The switches you created should be static.

See also

Applies to

.NET 9 ja muud versioonid
Toode Versioonid
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

BooleanSwitch(String, String, String)

Source:
BooleanSwitch.cs
Source:
BooleanSwitch.cs
Source:
BooleanSwitch.cs

Initializes a new instance of the BooleanSwitch class with the specified display name, description, and default switch value.

public BooleanSwitch (string displayName, string? description, string defaultSwitchValue);
public BooleanSwitch (string displayName, string description, string defaultSwitchValue);

Parameters

displayName
String

The name to display on the user interface.

description
String

The description of the switch.

defaultSwitchValue
String

The default value of the switch.

Applies to

.NET 9 ja muud versioonid
Toode Versioonid
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1