次の方法で共有


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の値によって決まります。

適用対象

こちらもご覧ください