スイッチを有効にするか無効にするかを指定します。
Public Property Enabled As Boolean
[C#]
public bool Enabled {get; set;}
[C++]
public: __property bool get_Enabled();public: __property void set_Enabled(bool);
[JScript]
public function get Enabled() : Boolean;public function set Enabled(Boolean);
プロパティ値
スイッチを有効にする場合は true 。それ以外の場合は false 。既定値は false です。
解説
既定では、このフィールドは false (無効) に設定されます。スイッチを有効にするには、このフィールドに値 true を設定します。スイッチを無効にするには、このフィールドに値 false を設定します。
使用例
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
[C#]
//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");
}
[C++]
public __gc class BooleanSwitchTest
{
/* Create a BooleanSwitch for data.*/
static BooleanSwitch* dataSwitch = new BooleanSwitch(S"Data", S"DataAccess module");
public:
static void MyMethod(String* location) {
//Insert code here to handle processing.
if(dataSwitch->Enabled)
Console::WriteLine(S"Error happened at {0}", location);
}
};
int main() {
//Run the method that writes an error message specifying the location of the error.
BooleanSwitchTest::MyMethod(S"in main");
}
[JScript]
//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");
}
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
BooleanSwitch クラス | BooleanSwitch メンバ | System.Diagnostics 名前空間 | BooleanSwitch | Switch | Debug | Trace