7 internal static class LocalAppContext
9 private delegate
bool TryGetSwitchDelegate(
string switchName, out
bool value);
11 private static TryGetSwitchDelegate TryGetSwitchFromCentralAppContext;
13 private static bool s_canForwardCalls;
17 private static readonly
object s_syncLock;
19 private static bool DisableCaching
25 static LocalAppContext()
28 s_syncLock =
new object();
29 s_canForwardCalls = SetupDelegate();
31 DisableCaching = IsSwitchEnabled(
"TestSwitch.LocalAppContext.DisableCaching");
34 public static bool IsSwitchEnabled(
string switchName)
36 if (s_canForwardCalls && TryGetSwitchFromCentralAppContext(switchName, out
bool value))
40 return IsSwitchEnabledLocal(switchName);
43 private static bool IsSwitchEnabledLocal(
string switchName)
49 flag = s_switchMap.
TryGetValue(switchName, out value);
58 private static bool SetupDelegate()
60 Type type = typeof(
object).Assembly.GetType(
"System.AppContext");
68 typeof(bool).MakeByRefType()
74 TryGetSwitchFromCentralAppContext = (TryGetSwitchDelegate)
Delegate.CreateDelegate(typeof(TryGetSwitchDelegate), method);
79 internal static bool GetCachedSwitchValue(
string switchName, ref
int switchValue)
89 return GetCachedSwitchValueInternal(switchName, ref switchValue);
92 private static bool GetCachedSwitchValueInternal(
string switchName, ref
int switchValue)
96 return IsSwitchEnabled(switchName);
98 bool flag = IsSwitchEnabled(switchName);
99 switchValue = (flag ? 1 : (-1));
103 internal static void DefineSwitchDefault(
string switchName,
bool initialValue)
105 s_switchMap[switchName] = initialValue;
Discovers the attributes of a method and provides access to method metadata.
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
MethodImplOptions
Defines the details of how a method is implemented.
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
Attribute can be applied to a delegate.