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
,这将输出错误消息和发生错误的位置。
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 that writes an error message specifying the location of the error.
BooleanSwitchTest::MyMethod( "in 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 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的值确定。