BooleanSwitch 생성자

정의

BooleanSwitch 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
BooleanSwitch(String, String)

지정된 표시 이름 및 설명을 사용하여 클래스의 BooleanSwitch 새 인스턴스를 초기화합니다.

BooleanSwitch(String, String, String)

지정된 표시 이름, 설명 및 기본 스위치 값을 사용하여 클래스의 BooleanSwitch 새 인스턴스를 초기화합니다.

BooleanSwitch(String, String)

지정된 표시 이름 및 설명을 사용하여 클래스의 BooleanSwitch 새 인스턴스를 초기화합니다.

public:
 BooleanSwitch(System::String ^ displayName, System::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)

매개 변수

displayName
String

사용자 인터페이스에 표시할 이름입니다.

description
String

스위치에 대한 설명입니다.

예제

다음 예제에서는 오류 BooleanSwitch 메시지를 인쇄할지 여부를 결정하는 스위치를 만들고 사용합니다. 스위치는 클래스 수준에서 만들어집니다. 메서드는 Main 오류 메시지를 출력하고 오류가 발생한 위치에 해당 위치를 MyMethod전달합니다.

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

설명

BooleanSwitch 만들 때 displayName 매개 변수를 사용하여 애플리케이션 구성 파일에서 .NET Framework 앱에 대한 초기 스위치 설정을 찾습니다. 생성자가 초기 설정을 찾을 수 없거나 .NET Core 및 .NET 5개 이상의 앱에 대해 Enabled 속성이 false(사용 안 함)으로 설정됩니다.

.NET Framework 앱에서 BooleanSwitch 수준을 설정하려면 애플리케이션의 이름에 해당하는 구성 파일을 편집합니다. 이 파일 내에서 스위치를 추가하고 해당 값을 설정하거나, 스위치를 제거하거나, 이전에 애플리케이션에서 설정한 모든 스위치를 지울 수 있습니다. 구성 파일의 형식은 다음 예제와 같이 지정해야 합니다.

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

메모

만든 스위치는 .이어야 static합니다.

추가 정보

적용 대상

BooleanSwitch(String, String, String)

지정된 표시 이름, 설명 및 기본 스위치 값을 사용하여 클래스의 BooleanSwitch 새 인스턴스를 초기화합니다.

public:
 BooleanSwitch(System::String ^ displayName, System::String ^ description, System::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)

매개 변수

displayName
String

사용자 인터페이스에 표시할 이름입니다.

description
String

스위치에 대한 설명입니다.

defaultSwitchValue
String

스위치의 기본값입니다.

적용 대상