Export (0) Print
Expand All

BooleanSwitch.Enabled Property

Gets or sets a value indicating whether the switch is enabled or disabled.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public bool Enabled { get; set; }
/** @property */
public boolean get_Enabled ()

/** @property */
public void set_Enabled (boolean value)

public function get Enabled () : boolean

public function set Enabled (value : boolean)

Not applicable.

Property Value

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

Exception typeCondition

SecurityException

The caller does not have the correct permission.

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 the value to false. The value of this property is determined by the value of the base class property SwitchSetting.

NoteNote:

This method uses the SecurityAction.LinkDemand flag to prevent being called from untrusted code; only the immediate caller is required to have SecurityPermissionAttribute.UnmanagedCode permission. If your code can be called from partially trusted code, do not pass the user input to Marshal class methods without validation. For important limitations on using the LinkDemand member, see Demand vs. LinkDemand.

The following code 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.

//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 static BooleanSwitch dataSwitch = 
    new BooleanSwitch("Data", "DataAccess module");

public static void MyMethod(String location)
{
    //Insert code here to handle processing.
    if (dataSwitch.get_Enabled()) {
        Console.WriteLine("Error happened at " + location);
    }
} //MyMethod

public static void main(String[] args)
{
    // Run the method that writes an error message specifying the location
    // of the error.
    MyMethod("in main");
} //main

//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");
 }
 

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft