9 private enum SwitchValueState
13 HasLookedForOverride = 0x4,
19 private static volatile bool s_defaultsInitialized =
false;
37 private static void InitializeDefaultSwitchValues()
41 if (!s_defaultsInitialized)
43 AppContextDefaultValues.PopulateDefaultValues();
44 s_defaultsInitialized =
true;
58 public static bool TryGetSwitch(
string switchName, out
bool isEnabled)
60 if (switchName ==
null)
64 if (switchName.Length == 0)
68 if (!s_defaultsInitialized)
70 InitializeDefaultSwitchValues();
75 if (s_switchMap.TryGetValue(switchName, out SwitchValueState value))
77 if (value == SwitchValueState.UnknownValue)
82 isEnabled = ((value & SwitchValueState.HasTrueValue) == SwitchValueState.HasTrueValue);
83 if ((value & SwitchValueState.HasLookedForOverride) == SwitchValueState.HasLookedForOverride)
87 if (AppContextDefaultValues.TryGetSwitchOverride(switchName, out
bool overrideValue))
89 isEnabled = overrideValue;
91 s_switchMap[switchName] = (SwitchValueState)(((!isEnabled) ? 1 : 2) | 4);
94 if (AppContextDefaultValues.TryGetSwitchOverride(switchName, out
bool overrideValue2))
96 isEnabled = overrideValue2;
97 s_switchMap[switchName] = (SwitchValueState)(((!isEnabled) ? 1 : 2) | 4);
100 s_switchMap[switchName] = SwitchValueState.UnknownValue;
112 public static void SetSwitch(
string switchName,
bool isEnabled)
114 if (switchName ==
null)
118 if (switchName.Length == 0)
122 if (!s_defaultsInitialized)
124 InitializeDefaultSwitchValues();
126 SwitchValueState value = (SwitchValueState)(((!isEnabled) ? 1 : 2) | 4);
129 s_switchMap[switchName] = value;
133 internal static void DefineSwitchDefault(
string switchName,
bool isEnabled)
135 s_switchMap[switchName] = ((!isEnabled) ? SwitchValueState.HasFalseValue : SwitchValueState.HasTrueValue);
138 internal static void DefineSwitchOverride(
string switchName,
bool isEnabled)
140 s_switchMap[switchName] = (SwitchValueState)(((!isEnabled) ? 1 : 2) | 4);
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Provides members for setting and retrieving data about an application's context.
string TargetFrameworkName
Gets or sets a string that specifies the target version and profile of the .NET Framework for the app...
string BaseDirectory
Gets the base directory that the assembly resolver uses to probe for assemblies.
static bool TryGetSwitch(string switchName, out bool isEnabled)
Tries to get the value of a switch.
static AppDomain CurrentDomain
Gets the current application domain for the current T:System.Threading.Thread.
Represents an application domain, which is an isolated environment where applications execute....
Provides information about, and means to manipulate, the current environment and platform....
static string BaseDirectory
Gets the pathname of the base directory that the assembly resolver uses to probe for assemblies.
AppDomainSetup SetupInformation
Gets the application domain configuration information for this instance.
static void SetSwitch(string switchName, bool isEnabled)
Sets the value of a switch.
The exception that is thrown when one of the arguments provided to a method is not valid.
static object GetData(string name)
Returns the value of the named data element assigned to the current application domain.
object GetData(string name)
Gets the value stored in the current application domain for the specified name.
static string TargetFrameworkName
Gets the name of the framework version targeted by the current application.