BooleanSwitch コンストラクター

定義

BooleanSwitch クラスの新しいインスタンスを初期化します。

オーバーロード

名前 説明
BooleanSwitch(String, String)

指定した表示名と説明を使用して、 BooleanSwitch クラスの新しいインスタンスを初期化します。

BooleanSwitch(String, String, String)

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

BooleanSwitch(String, String)

ソース:
BooleanSwitch.cs
ソース:
BooleanSwitch.cs
ソース:
BooleanSwitch.cs
ソース:
BooleanSwitch.cs
ソース:
BooleanSwitch.cs

指定した表示名と説明を使用して、 BooleanSwitch クラスの新しいインスタンスを初期化します。

public:
 BooleanSwitch(System::String ^ displayName, System::String ^ description);
public BooleanSwitch(string displayName, string? description);
public BooleanSwitch(string displayName, string description);
new System.Diagnostics.BooleanSwitch : string * string -> System.Diagnostics.BooleanSwitch
Public Sub New (displayName As String, description As String)

パラメーター

displayName
String

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

description
String

スイッチの説明。

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

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

注釈

BooleanSwitchを作成すると、displayName パラメーターを使用して、アプリケーション構成ファイル内の .NET Framework アプリの初期スイッチ設定が検索されます。 コンストラクターが初期設定を見つけられない場合、または .NET Core および .NET 5 以上のアプリの場合、Enabled プロパティは false (無効) に設定されます。

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

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

Note

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

こちらもご覧ください

適用対象

BooleanSwitch(String, String, String)

ソース:
BooleanSwitch.cs
ソース:
BooleanSwitch.cs
ソース:
BooleanSwitch.cs
ソース:
BooleanSwitch.cs
ソース:
BooleanSwitch.cs

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

public:
 BooleanSwitch(System::String ^ displayName, System::String ^ description, System::String ^ defaultSwitchValue);
public BooleanSwitch(string displayName, string? description, string defaultSwitchValue);
public BooleanSwitch(string displayName, string description, string defaultSwitchValue);
new System.Diagnostics.BooleanSwitch : string * string * string -> System.Diagnostics.BooleanSwitch
Public Sub New (displayName As String, description As String, defaultSwitchValue As String)

パラメーター

displayName
String

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

description
String

スイッチの説明。

defaultSwitchValue
String

スイッチの既定値。

適用対象