BooleanSwitch Construtores
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Inicializa uma nova instância da classe BooleanSwitch.
Sobrecargas
| Nome | Description |
|---|---|
| BooleanSwitch(String, String) |
Inicializa uma nova instância da BooleanSwitch classe com o nome de exibição e a descrição especificados. |
| BooleanSwitch(String, String, String) |
Inicializa uma nova instância da BooleanSwitch classe com o nome de exibição, a descrição e o valor de comutador padrão especificados. |
BooleanSwitch(String, String)
- Origem:
- BooleanSwitch.cs
- Origem:
- BooleanSwitch.cs
- Origem:
- BooleanSwitch.cs
- Origem:
- BooleanSwitch.cs
- Origem:
- BooleanSwitch.cs
Inicializa uma nova instância da BooleanSwitch classe com o nome de exibição e a descrição especificados.
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)
Parâmetros
- displayName
- String
O nome a ser exibido em uma interface do usuário.
- description
- String
A descrição da opção.
Exemplos
O exemplo a seguir cria um BooleanSwitch e usa a opção para determinar se uma mensagem de erro deve ser impressa. A opção é criada no nível da classe. O Main método passa seu local para MyMethod, o que imprime uma mensagem de erro e onde o erro ocorreu.
// 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
Comentários
Quando você cria um BooleanSwitch, o parâmetro displayName é usado para localizar as configurações de comutador iniciais para aplicativos do .NET Framework no arquivo de configuração do aplicativo. Se o construtor não conseguir encontrar as configurações iniciais ou .NET Core e .NET mais de 5 aplicativos, a propriedade Enabled será definida como false (desabilitado).
Para definir o nível do BooleanSwitch em um aplicativo .NET Framework, edite o arquivo de configuração correspondente ao nome do aplicativo. Nesse arquivo, você pode adicionar uma opção e definir seu valor, remover uma opção ou limpar todas as opções definidas anteriormente pelo aplicativo. O arquivo de configuração deve ser formatado como o exemplo a seguir:
<configuration>
<system.diagnostics>
<switches>
<add name="mySwitch" value="10" />
<add name="myNewSwitch" value="20" />
<remove name="mySwitch" />
<clear/>
</switches>
</system.diagnostics>
</configuration>
Note
As opções que você criou devem ser static.
Confira também
Aplica-se a
BooleanSwitch(String, String, String)
- Origem:
- BooleanSwitch.cs
- Origem:
- BooleanSwitch.cs
- Origem:
- BooleanSwitch.cs
- Origem:
- BooleanSwitch.cs
- Origem:
- BooleanSwitch.cs
Inicializa uma nova instância da BooleanSwitch classe com o nome de exibição, a descrição e o valor de comutador padrão especificados.
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)
Parâmetros
- displayName
- String
O nome a ser exibido na interface do usuário.
- description
- String
A descrição da opção.
- defaultSwitchValue
- String
O valor padrão da opção.