BooleanSwitch.Enabled プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > BooleanSwitch.Enabled プロパティの意味・解説 

BooleanSwitch.Enabled プロパティ

スイッチが有効または無効かを示す値を取得または設定します。

名前空間: System.Diagnostics
アセンブリ: System (system.dll 内)
構文構文

例外例外
解説解説

既定では、このフィールドは false (無効) に設定されます。スイッチを有効にするには、このフィールドに値 true を設定します。スイッチを無効にするには、値を false に設定します。このプロパティの値は、基本クラス プロパティ SwitchSetting の値によって決まります。

メモメモ

このメソッドは SecurityAction.LinkDemand フラグを使用して、信頼関係のないコードからの呼び出しを防ぎます。SecurityPermissionAttribute.UnmanagedCode アクセス許可は、直前の呼び出し元にのみ要求されます。信頼性が一部しか確認されていないコードから呼び出すことができるコードの場合、ユーザー入力を検証せずに Marshal クラスに渡すことは避けてください。LinkDemand メンバの使用に関する重要な制約事項については、「Demand と LinkDemand」を参照してください。

使用例使用例

BooleanSwitch を作成し、スイッチを使用してエラー メッセージを出力するかどうかを決定するコード例を次に示します。スイッチはクラス レベルで作成されます。Main メソッドは、その位置をエラー メッセージとエラーの発生場所を出力する MyMethod に渡します。

'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 のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

BooleanSwitch.Enabled プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



BooleanSwitch.Enabled プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS