Freigeben über


BooleanSwitch.Enabled-Eigenschaft

Ruft einen Wert ab, der angibt, ob der Schalter aktiviert ist, oder legt diesen fest.

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

Syntax

'Declaration
Public Property Enabled As Boolean
'Usage
Dim instance As BooleanSwitch
Dim value As Boolean

value = instance.Enabled

instance.Enabled = value
public bool Enabled { get; set; }
public:
property bool Enabled {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_Enabled ()

/** @property */
public void set_Enabled (boolean value)
public function get Enabled () : boolean

public function set Enabled (value : boolean)

Eigenschaftenwert

true, wenn der Schalter aktiviert ist, andernfalls false. Der Standardwert ist false.

Ausnahmen

Ausnahmetyp Bedingung

SecurityException

Der Aufrufer verfügt nicht über die erforderliche Berechtigung.

Hinweise

Dieses Feld ist in der Standardeinstellung auf false (deaktiviert) festgelegt. Um den Schalter zu aktivieren, weisen Sie dem Feld den Wert true zu. Um den Schalter zu deaktivieren, weisen Sie den Wert false zu. Der Wert dieser Eigenschaft wird durch den Wert der Basisklasseneigenschaft SwitchSetting bestimmt.

Hinweis

Diese Methode verwendet das SecurityAction.LinkDemand-Flag, um einen Aufruf aus nicht vertrauenswürdigem Code zu verhindern. Nur der direkte Aufrufer muss über die SecurityPermissionAttribute.UnmanagedCode-Berechtigung verfügen. Wenn der Code aus teilweise vertrauenswürdigem Code aufgerufen werden kann, dürfen Benutzereingaben nicht ohne Validierung an Methoden der Marshal-Klasse übergeben werden. Wichtige Einschränkungen bei der Verwendung des LinkDemand-Members finden Sie unter "Demand" und "LinkDemand".

Beispiel

Im folgenden Codebeispiel wird ein BooleanSwitch erstellt und mit diesem Schalter bestimmt, ob eine Fehlermeldung angezeigt werden soll. Der Schalter wird auf Klassenebene erstellt. Die Main-Methode übergibt ihre Position an MyMethod, die eine Fehlermeldung und die Position des Fehlers ausgibt.

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

.NET Framework-Sicherheit

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

BooleanSwitch-Klasse
BooleanSwitch-Member
System.Diagnostics-Namespace
BooleanSwitch-Klasse
Switch
Debug
Trace