LocalAppContextSwitches
using System.Runtime.CompilerServices;
namespace System
{
[NullableContext(1)]
[Nullable(0)]
internal static class LocalAppContextSwitches
{
private static int s_dontSupportPngFramesInIcons;
private static int s_optimizePrintPreview;
public static bool DontSupportPngFramesInIcons {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
return GetCachedSwitchValue("Switch.System.Drawing.DontSupportPngFramesInIcons", ref s_dontSupportPngFramesInIcons);
}
}
public static bool OptimizePrintPreview {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
return GetCachedSwitchValue("Switch.System.Drawing.Printing.OptimizePrintPreview", ref s_optimizePrintPreview);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool GetSwitchValue(string switchName, ref bool switchValue)
{
return AppContext.TryGetSwitch(switchName, out switchValue);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool GetCachedSwitchValue(string switchName, ref int cachedSwitchValue)
{
int num = cachedSwitchValue;
if (num < 0)
return false;
if (num > 0)
return true;
return GetCachedSwitchValueInternal(switchName, ref cachedSwitchValue);
}
private static bool GetCachedSwitchValueInternal(string switchName, ref int cachedSwitchValue)
{
if (!AppContext.TryGetSwitch(switchName, out bool isEnabled))
isEnabled = GetSwitchDefaultValue(switchName);
AppContext.TryGetSwitch("TestSwitch.LocalAppContext.DisableCaching", out bool isEnabled2);
if (!isEnabled2)
cachedSwitchValue = (isEnabled ? 1 : (-1));
return isEnabled;
}
private static bool GetSwitchDefaultValue(string switchName)
{
if (switchName == "Switch.System.Runtime.Serialization.SerializationGuard")
return true;
if (switchName == "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization")
return true;
return false;
}
}
}