BooleanSwitchとは? わかりやすく解説

BooleanSwitch クラス

デバッグおよびトレース出力制御する単純なオン/オフ スイッチ提供します

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

Public Class BooleanSwitch
    Inherits Switch
Dim instance As BooleanSwitch
public class BooleanSwitch : Switch
public ref class BooleanSwitch : public
 Switch
public class BooleanSwitch extends Switch
public class BooleanSwitch extends
 Switch
解説解説

ブール型トレース使用しメッセージ重要性基づいてメッセージの有効と無効切り替えることができますEnabled プロパティ使用してスイッチ現在の値を取得します

アプリケーション構成ファイルBooleanSwitch を有効または無効にし、構成した BooleanSwitch 値をアプリケーション使用できます。または、BooleanSwitchコード内に作成しEnabled プロパティ直接設定してコード特定のセクションインストルメントすることもできます

BooleanSwitch構成するには、アプリケーションの名前に対応した構成ファイル編集します。このファイルでは、スイッチ追加または削除スイッチの値の設定アプリケーション以前設定されすべてのスイッチクリア実行できます構成ファイル書式次の例のとおりです。

<configuration>
  <system.diagnostics>
    <switches>
      <add name="mySwitch" value="1"/>
    </switches>
  </system.diagnostics>
</configuration>

この例の構成セクションBooleanSwitch定義するには、DisplayName プロパティmySwitch設定しEnabled 値を true設定しますアプリケーション内で、構成したスイッチ値を使用するには、次のコード例に示すように BooleanSwitch を同じ名前で作成します

Private Shared boolSwitch As
 New BooleanSwitch("mySwitch",
 _
    "Switch in config file")

Public Shared Sub Main(ByVal
 CmdArgs() As String)
    '...
    Console.WriteLine("Boolean switch {0} configured as {1}",
 _
        boolSwitch.DisplayName, boolSwitch.Enabled.ToString())
    If boolSwitch.Enabled Then
        '...
    End If

End Sub
private static BooleanSwitch boolSwitch = new
 BooleanSwitch("mySwitch", 
    "Switch in config file");

public static void Main(string[]
 args) 
{
    //...
    Console.WriteLine("Boolean switch {0} configured as {1}",
 
        boolSwitch.DisplayName, boolSwitch.Enabled.ToString());
    if (boolSwitch.Enabled)
    {
        //...
    }
}

既定では、Enabled プロパティ構成ファイル指定した値を使用して設定されます。Enabled プロパティfalse設定するにはスイッチに値 0 を設定しEnabled プロパティtrue設定するにはスイッチを 0 以外に設定しますBooleanSwitch コンストラクタ構成ファイル初期スイッチ設定検出できない場合新しスイッチEnabled プロパティ既定false設定されます。

スイッチ使用するには、トレースまたはデバッグ有効にする必要があります次の構文コンパイラ固有です。C# または Visual Basic 以外のコンパイラ使用する場合は、使用するコンパイラドキュメント参照してください

メモメモ

これらのデバッグおよびトレースコンパイラ スイッチは、BooleanSwitch クラス単独使用する場合には必要ありません。これらが必要になるのは、Trace クラスまたは Debug クラス条件付きコンパイルされたメソッド組み合わせて使用する場合だけです。

アプリケーション導入詳細については、Debug および Traceトピック参照してくださいトレース スイッチ構成と使用詳細については、「トレース スイッチ」を参照してください

メモメモ

クラスBooleanSwitchメンバstatic にすることで、パフォーマンス向上させることができます

使用例使用例

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 function.
Public Overloads Shared
 Sub Main()
    Main(System.Environment.GetCommandLineArgs())
End Sub
 
Overloads Public Shared
 Sub Main(args() As String)
    ' Run the method which 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 which 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 which 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 which 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() {
    // Run the method which writes an error message specifying the location
 of the error.
    MyMethod("in Main");
 }

継承階層継承階層
System.Object
   System.Diagnostics.Switch
    System.Diagnostics.BooleanSwitch
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

BooleanSwitch コンストラクタ (String, String, String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

スイッチ表示名説明、および既定スイッチ値を指定して、BooleanSwitch クラス新しインスタンス初期化します。

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

Public Sub New ( _
    displayName As String, _
    description As String, _
    defaultSwitchValue As String _
)
Dim displayName As String
Dim description As String
Dim defaultSwitchValue As String

Dim instance As New BooleanSwitch(displayName,
 description, defaultSwitchValue)
public BooleanSwitch (
    string displayName,
    string description,
    string defaultSwitchValue
)
public:
BooleanSwitch (
    String^ displayName, 
    String^ description, 
    String^ defaultSwitchValue
)
public BooleanSwitch (
    String displayName, 
    String description, 
    String defaultSwitchValue
)
public function BooleanSwitch (
    displayName : String, 
    description : String, 
    defaultSwitchValue : String
)

パラメータ

displayName

ユーザー インターフェイス表示する名前。

description

スイッチ説明

defaultSwitchValue

スイッチ既定値

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

BooleanSwitch コンストラクタ


BooleanSwitch コンストラクタ (String, String)

表示名説明指定して、BooleanSwitch クラス新しインスタンス初期化します。

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

解説解説

BooleanSwitch作成するときは、スイッチ初期設定値検索displayName パラメータ使用されます。コンストラクタ初期設定値を見つけることができなかった場合Enabled プロパティfalse (無効) に設定されます。

BooleanSwitchレベル設定するには、アプリケーション名に対応する構成ファイル編集します。このファイル内で、スイッチ追加スイッチの値の設定スイッチ削除、そのアプリケーション以前設定したすべてのスイッチクリアなどを行うことができます構成ファイル書式次の例のようになります

 <configuration>
     <system.diagnostics>
        <switches>
           <add name="mySwitch" value="10" />
           <add name="myNewSwitch" value="20" />
           <remove name="mySwitch" />
           <clear/>
        </switches>
     </system.diagnostics>
  </configuration>
メモメモ

作成したスイッチstatic にする必要があります

使用例使用例

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 function.
Public Overloads Shared
 Sub Main()
    Main(System.Environment.GetCommandLineArgs())
End Sub
 
Overloads Public Shared
 Sub Main(args() As String)
    ' Run the method which 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 which 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 which 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 which 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() {
    // Run the method which writes an error message specifying the location
 of the error.
    MyMethod("in Main");
 }

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

BooleanSwitch プロパティ


BooleanSwitch プロパティ


BooleanSwitch メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

BooleanSwitch クラス
System.Diagnostics 名前空間
Switch
TraceSwitch
Debug
Trace

BooleanSwitch メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

BooleanSwitch クラス
System.Diagnostics 名前空間
Switch
TraceSwitch
Debug
Trace

BooleanSwitch メンバ

デバッグおよびトレース出力制御する単純なオン/オフ スイッチ提供します

BooleanSwitch データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
プロテクト プロパティプロテクト プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

BooleanSwitch クラス
System.Diagnostics 名前空間
Switch
TraceSwitch
Debug
Trace


このページでは「.NET Framework クラス ライブラリ リファレンス」からBooleanSwitchを検索した結果を表示しています。
Weblioに収録されているすべての辞書からBooleanSwitchを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からBooleanSwitch を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「BooleanSwitch」の関連用語

BooleanSwitchのお隣キーワード
検索ランキング

   

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



BooleanSwitchのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS