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

속성 값

스위치를 사용하면 true이고, 사용하지 않으면 false입니다. 기본값은 false입니다.

예외

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

예제

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

public ref class BooleanSwitchTest
{
private:

   /* Create a BooleanSwitch for data.*/
   static BooleanSwitch^ dataSwitch = gcnew BooleanSwitch( "Data","DataAccess module" );

public:
   static void MyMethod( String^ location )
   {
      
      //Insert code here to handle processing.
      if ( dataSwitch->Enabled )
            Console::WriteLine( "Error happened at {0}", location );
   }

};

int main()
{
   
   //Run the method that writes an error message specifying the location of the error.
   BooleanSwitchTest::MyMethod( "in main" );
}
//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합니다.

적용 대상

추가 정보