BooleanSwitch Constructeurs

Définition

Initialise une nouvelle instance de la classe BooleanSwitch.

Surcharges

Nom Description
BooleanSwitch(String, String)

Initialise une nouvelle instance de la BooleanSwitch classe avec le nom complet et la description spécifiés.

BooleanSwitch(String, String, String)

Initialise une nouvelle instance de la BooleanSwitch classe avec le nom d’affichage, la description et la valeur de commutateur par défaut spécifiés.

BooleanSwitch(String, String)

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

Initialise une nouvelle instance de la BooleanSwitch classe avec le nom complet et la description spécifiés.

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)

Paramètres

displayName
String

Nom à afficher sur une interface utilisateur.

description
String

Description du commutateur.

Exemples

L’exemple suivant crée un BooleanSwitch commutateur et utilise le commutateur pour déterminer s’il faut imprimer un message d’erreur. Le commutateur est créé au niveau de la classe. La Main méthode transmet son emplacement à MyMethod, qui imprime un message d’erreur et où l’erreur s’est produite.

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

Remarques

Lorsque vous créez un BooleanSwitch, le paramètre displayName est utilisé pour rechercher les paramètres de commutateur initial pour les applications .NET Framework dans le fichier de configuration de l’application. Si le constructeur ne trouve pas les paramètres initiaux ou pour les applications .NET Core et .NET 5+, la propriété Enabled est définie sur false (désactivé).

Pour définir le niveau de votre BooleanSwitch dans une application .NET Framework, modifiez le fichier de configuration correspondant au nom de votre application. Dans ce fichier, vous pouvez ajouter un commutateur et définir sa valeur, supprimer un commutateur ou effacer tous les commutateurs précédemment définis par l’application. Le fichier de configuration doit être mis en forme comme dans l’exemple suivant :

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

Note

Les commutateurs que vous avez créés doivent être static.

Voir aussi

S’applique à

BooleanSwitch(String, String, String)

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

Initialise une nouvelle instance de la BooleanSwitch classe avec le nom d’affichage, la description et la valeur de commutateur par défaut spécifiés.

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)

Paramètres

displayName
String

Nom à afficher sur l’interface utilisateur.

description
String

Description du commutateur.

defaultSwitchValue
String

Valeur par défaut du commutateur.

S’applique à