BooleanSwitch.Enabled 속성

정의

스위치의 사용 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool Enabled { bool get(); void set(bool value); };
public bool Enabled { get; set; }
member this.Enabled : bool with get, set
Public Property Enabled As Boolean

속성 값

스위치를 사용하도록 설정하면 기본값은 false입니다.

예외

호출자에게 올바른 권한이 없습니다.

예제

다음 코드 예제에서는 오류 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 that 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 Private Function
Public Overloads Shared Sub Main()
    Main(System.Environment.GetCommandLineArgs())
End Sub
 
Overloads Public Shared Sub Main(args() As String)
    'Run the method that writes an error message specifying the location of the error.
    MyMethod("in Main")
End Sub

설명

기본적으로 이 필드는 (사용 안 함)으로 false 설정됩니다. 스위치를 사용하도록 설정하려면 이 필드에 값을 할당합니다 true. 스위치를 사용하지 않도록 설정하려면 값을 .에 할당합니다 false. 이 속성의 값은 기본 클래스 속성 SwitchSetting의 값에 의해 결정됩니다.

적용 대상

추가 정보