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的值确定。

适用于

另请参阅