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:
property bool Enabled {
	bool get ();
	void set (bool value);
}

Property Value

Type: System::Boolean
true if the switch is enabled; otherwise, false. The default is false.

ExceptionCondition
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.

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft