BooleanSwitch.Enabled 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是启用或禁用开关。
public:
property bool Enabled { bool get(); void set(bool value); };
public bool Enabled { get; set; }
member this.Enabled : bool with get, set
Public Property Enabled As Boolean
属性值
true 如果启用开关,则为否则,为 false. 默认值为 false。
例外
调用方没有正确的权限。
示例
下面的代码示例创建一个 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 that 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 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
注解
默认情况下,此字段设置为 false “已禁用”。 若要启用开关,请为此字段分配值 true。 若要禁用开关,请将值赋给 false。 此属性的值由基类属性 SwitchSetting的值确定。