BooleanSwitch クラス
アセンブリ: System (system.dll 内)


ブール型トレースを使用し、メッセージの重要性に基づいてメッセージの有効と無効を切り替えることができます。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 以外のコンパイラを使用する場合は、使用するコンパイラのドキュメントを参照してください。
-
C# でデバッグを有効にするには、コードのコンパイル時に /d:DEBUG フラグをコンパイラのコマンド ラインに追加するか、#define DEBUG をファイルの最上部に挿入します。Visual Basic では、コンパイラのコマンド ラインに /d:DEBUG=True フラグを追加します。
-
C# でトレースを有効にするには、コードのコンパイル時に /d:TRACE フラグをコンパイラのコマンド ラインに追加するか、#define TRACE をファイルの最上部に挿入します。Visual Basic では、コンパイラのコマンド ラインに /d:TRACE=True フラグを追加します。
![]() |
---|
これらのデバッグおよびトレースのコンパイラ スイッチは、BooleanSwitch クラスを単独で使用する場合には必要ありません。これらが必要になるのは、Trace クラスまたは Debug クラスの条件付きコンパイルされたメソッドと組み合わせて使用する場合だけです。 |
アプリケーション導入の詳細については、Debug および Trace のトピックを参照してください。トレース スイッチの構成と使用の詳細については、「トレース スイッチ」を参照してください。

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.Diagnostics.Switch
System.Diagnostics.BooleanSwitch


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


BooleanSwitch コンストラクタ (String, String, String)
アセンブリ: 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 パラメータは DisplayName プロパティの値を設定するために使用され、description パラメータは Description プロパティの値を設定するために使用されます。defaultSwitchValue パラメータはフィールドとして保存され、Value プロパティを初期化するために最初の参照時に使用されます。コンストラクタの使用の詳細については、BooleanSwitch(String,String) コンストラクタのトピックを参照してください。

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


BooleanSwitch コンストラクタ

名前 | 説明 |
---|---|
BooleanSwitch (String, String) | 表示名と説明を指定して、BooleanSwitch クラスの新しいインスタンスを初期化します。 |
BooleanSwitch (String, String, String) | スイッチの表示名、説明、および既定のスイッチ値を指定して、BooleanSwitch クラスの新しいインスタンスを初期化します。 |

BooleanSwitch コンストラクタ (String, String)
アセンブリ: System (system.dll 内)

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

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>
![]() |
---|

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"); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


BooleanSwitch プロパティ

名前 | 説明 | |
---|---|---|
![]() | Attributes | アプリケーション構成ファイルに定義されているカスタム スイッチ属性を取得します。 ( Switch から継承されます。) |
![]() | Description | スイッチの説明を取得します。 ( Switch から継承されます。) |
![]() | DisplayName | スイッチを識別するための名前を取得します。 ( Switch から継承されます。) |
![]() | Enabled | スイッチが有効または無効かを示す値を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | SwitchSetting | このスイッチの現在の設定を取得または設定します。 ( Switch から継承されます。) |
![]() | Value | スイッチの値を取得または設定します。 ( Switch から継承されます。) |

BooleanSwitch プロパティ

名前 | 説明 | |
---|---|---|
![]() | Attributes | アプリケーション構成ファイルに定義されているカスタム スイッチ属性を取得します。 ( Switch から継承されます。) |
![]() | Description | スイッチの説明を取得します。 ( Switch から継承されます。) |
![]() | DisplayName | スイッチを識別するための名前を取得します。 ( Switch から継承されます。) |
![]() | Enabled | スイッチが有効または無効かを示す値を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | SwitchSetting | このスイッチの現在の設定を取得または設定します。 ( Switch から継承されます。) |
![]() | Value | スイッチの値を取得または設定します。 ( Switch から継承されます。) |

BooleanSwitch メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | GetSupportedAttributes | スイッチによってサポートされるカスタム属性を取得します。 ( Switch から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
![]() | OnSwitchSettingChanged | SwitchSetting プロパティが変更されると発生します。 ( Switch から継承されます。) |
![]() | OnValueChanged | オーバーライドされます。 Value プロパティの新しい値がブール値として解析されるかどうかを判断します。 |

BooleanSwitch メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | GetSupportedAttributes | スイッチによってサポートされるカスタム属性を取得します。 ( Switch から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
![]() | OnSwitchSettingChanged | SwitchSetting プロパティが変更されると発生します。 ( Switch から継承されます。) |
![]() | OnValueChanged | オーバーライドされます。 Value プロパティの新しい値がブール値として解析されるかどうかを判断します。 |

BooleanSwitch メンバ
デバッグおよびトレースの出力を制御する単純なオン/オフ スイッチを提供します。
BooleanSwitch データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Attributes | アプリケーション構成ファイルに定義されているカスタム スイッチ属性を取得します。(Switch から継承されます。) |
![]() | Description | スイッチの説明を取得します。(Switch から継承されます。) |
![]() | DisplayName | スイッチを識別するための名前を取得します。(Switch から継承されます。) |
![]() | Enabled | スイッチが有効または無効かを示す値を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | SwitchSetting | このスイッチの現在の設定を取得または設定します。(Switch から継承されます。) |
![]() | Value | スイッチの値を取得または設定します。(Switch から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | GetSupportedAttributes | スイッチによってサポートされるカスタム属性を取得します。 (Switch から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
![]() | OnSwitchSettingChanged | SwitchSetting プロパティが変更されると発生します。 (Switch から継承されます。) |
![]() | OnValueChanged | オーバーライドされます。 Value プロパティの新しい値がブール値として解析されるかどうかを判断します。 |

Weblioに収録されているすべての辞書からBooleanSwitchを検索する場合は、下記のリンクをクリックしてください。

- BooleanSwitchのページへのリンク