Export (0) Print
Expand All

BooleanSwitch.Enabled Property

Specifies whether the switch is enabled or disabled.

[Visual Basic]
Public Property Enabled As Boolean
[C#]
public bool Enabled {get; set;}
[C++]
public: __property bool get_Enabled();
public: __property void set_Enabled(bool);
[JScript]
public function get Enabled() : Boolean;
public function set Enabled(Boolean);

Property Value

true if the switch is enabled; otherwise, false. The default is false.

Remarks

By default, this field is set to false (disabled). To enable the switch, assign this field the value of true. To disable the switch, assign it false.

Example

The following example creates a BooleanSwitch and uses the switch to determine whether to print an error message. The switch is created at the class level. The Main method passes its location to MyMethod, which prints an error message and the location where the error occurred.

[Visual Basic] 
'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 'MyMethod

'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 'Main

[C#] 
//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");
 }
 

[C++] 
public __gc class BooleanSwitchTest
{
   /* Create a BooleanSwitch for data.*/
   static BooleanSwitch* dataSwitch = new BooleanSwitch(S"Data", S"DataAccess module");

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

int main() {
   //Run the method that writes an error message specifying the location of the error.
   BooleanSwitchTest::MyMethod(S"in main");
}


[JScript] 
//Class level declaration.
 /* Create a BooleanSwitch for data.*/
 static var dataSwitch : BooleanSwitch = new BooleanSwitch("Data", "DataAccess module");
 
 static public function MyMethod(location : String) {
    //Insert code here to handle processing.
    if(dataSwitch.Enabled)
       Console.WriteLine("Error happened at " + location);
 }
 
 public static function Main(args : String[]) {
    //Run the method that writes an error message specifying the location of the error.
    MyMethod("in Main");
 }
 

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

BooleanSwitch Class | BooleanSwitch Members | System.Diagnostics Namespace | BooleanSwitch | Switch | Debug | Trace

Show:
© 2015 Microsoft