A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/api/system.appcontext.setswitch below:

AppContext.SetSwitch(String, Boolean) Method (System) | Microsoft Learn

AppContext.SetSwitch(String, Boolean) Method Definition

Sets the value of a switch.

public:
 static void SetSwitch(System::String ^ switchName, bool isEnabled);
public static void SetSwitch(string switchName, bool isEnabled);
static member SetSwitch : string * bool -> unit
Public Shared Sub SetSwitch (switchName As String, isEnabled As Boolean)
Parameters
switchName
String

The name of the switch.

isEnabled
Boolean

The value of the switch.

Exceptions Examples

The following line of code sets a switch named Switch.AmazingLib.ThrowOnException to true, which enables a legacy behavior. The library can then check whether a library consumer has set the value of the switch by calling the TryGetSwitch method.

AppContext.SetSwitch("Switch.AmazingLib.ThrowOnException", true);
AppContext.SetSwitch("Switch.AmazingLib.ThrowOnException", true)
AppContext.SetSwitch("Switch.AmazingLib.ThrowOnException", True)
Remarks

The AppContext class enables library writers to provide a uniform opt-out mechanism for new functionality for their users. It establishes a loosely coupled contract between components in order to communicate an opt-out request. This capability is typically important when a change is made to existing functionality. Conversely, there is already an implicit opt-in for new functionality.

The SetSwitch method is called by an application (or a library) to declare the value of a switch (which is always a Boolean value) that a dependent library defines. The switch is always implicitly false, which provides the new behavior. Setting the switch to true enables it, which provides the legacy behavior. Explicitly setting the switch to false also provides the new behavior. The dependent library can then check the value of the switch by calling the TryGetSwitch method.

Note

It's beneficial to use a consistent format for switch names, since they are a formal contract exposed by a library. The following are two obvious formats.

For applications running on .NET Framework, in addition to setting the value of a switch programmatically, it can also be set:

If the registry entry exists, its value is overwritten by the isEnabled argument when SetSwitch is called. That is, the most recent call to the SetSwitch method overrides the value defined in the registry, in an app configuration file, or by previous calls to the SetSwitch method.

See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4