BooleanSwitch.Enabled Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value indicating whether the switch is enabled or disabled.
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
Property Value
true
if the switch is enabled; otherwise, false
. The default is false
.
Exceptions
The caller does not have the correct permission.
Examples
The following code example creates a BooleanSwitch and uses the switch to determine whether to print an error message. The switch is created at the class level. The Main
method passes its location to MyMethod
, which prints an error message and the location where the error occurred.
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
Remarks
By default, this field is set to false
(disabled). To enable the switch, assign this field the value of true
. To disable the switch, assign the value to false
. The value of this property is determined by the value of the base class property SwitchSetting.
Applies to
See also
Pripomienky
https://aka.ms/ContentUserFeedback.
Pripravujeme: V priebehu roka 2024 postupne zrušíme službu Problémy v službe GitHub ako mechanizmus pripomienok týkajúcich sa obsahu a nahradíme ju novým systémom pripomienok. Ďalšie informácie nájdete na stránke:Odoslať a zobraziť pripomienky pre