BooleanSwitch Construtores
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da BooleanSwitch classe.
Sobrecargas
| Name | Description |
|---|---|
| BooleanSwitch(String, String) |
Inicializa uma nova instância da BooleanSwitch classe com o nome e descrição especificados. |
| BooleanSwitch(String, String, String) |
Inicializa uma nova instância da BooleanSwitch classe com o nome de exibição especificado, descrição e valor padrão do switch. |
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 e 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 mostrar numa interface de utilizador.
- description
- String
A descrição da mudança.
Exemplos
O exemplo seguinte cria um BooleanSwitch e usa o interruptor para determinar se deve imprimir uma mensagem de erro. A troca é criada ao nível da turma. O Main método passa a sua localização para MyMethod, que imprime uma mensagem de erro e indica 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
Observações
Quando crias um BooleanSwitch, o parâmetro displayName é usado para encontrar as definições iniciais do switch para .NET aplicações Framework no ficheiro de configuração da aplicação. Se o construtor não conseguir encontrar as definições iniciais, ou para .NET Core e .NET 5+ apps, a propriedade Enabled é definida para false (desativada).
Para definir o nível do seu BooleanSwitch numa aplicação .NET Framework, edite o ficheiro de configuração correspondente ao nome da sua aplicação. Dentro deste ficheiro, pode adicionar um interruptor e definir o seu valor, remover um interruptor ou apagar todos os interruptores previamente definidos pela aplicação. O ficheiro de configuração deve ser formatado como o seguinte exemplo:
<configuration>
<system.diagnostics>
<switches>
<add name="mySwitch" value="10" />
<add name="myNewSwitch" value="20" />
<remove name="mySwitch" />
<clear/>
</switches>
</system.diagnostics>
</configuration>
Note
Os interruptores que criaste devem ser static.
Ver 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 especificado, descrição e valor padrão do switch.
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 mostrar na interface do utilizador.
- description
- String
A descrição da mudança.
- defaultSwitchValue
- String
O valor padrão do interruptor.