Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LocalAppContextSwitches.cs
Go to the documentation of this file.
2
3namespace System;
4
5internal static class LocalAppContextSwitches
6{
8
10 {
11 [MethodImpl(MethodImplOptions.AggressiveInlining)]
12 get
13 {
14 return GetCachedSwitchValue("Switch.System.Data.AllowArbitraryDataSetTypeInstantiation", ref s_allowArbitraryTypeInstantiation);
15 }
16 }
17
18 [MethodImpl(MethodImplOptions.AggressiveInlining)]
19 internal static bool GetCachedSwitchValue(string switchName, ref int cachedSwitchValue)
20 {
21 if (cachedSwitchValue < 0)
22 {
23 return false;
24 }
25 if (cachedSwitchValue > 0)
26 {
27 return true;
28 }
29 return GetCachedSwitchValueInternal(switchName, ref cachedSwitchValue);
30 }
31
32 private static bool GetCachedSwitchValueInternal(string switchName, ref int cachedSwitchValue)
33 {
34 if (!AppContext.TryGetSwitch(switchName, out var isEnabled))
35 {
36 isEnabled = GetSwitchDefaultValue(switchName);
37 }
38 AppContext.TryGetSwitch("TestSwitch.LocalAppContext.DisableCaching", out var isEnabled2);
39 if (!isEnabled2)
40 {
41 cachedSwitchValue = (isEnabled ? 1 : (-1));
42 }
43 return isEnabled;
44 }
45
46 private static bool GetSwitchDefaultValue(string switchName)
47 {
48 if (switchName == "Switch.System.Runtime.Serialization.SerializationGuard")
49 {
50 return true;
51 }
52 if (switchName == "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization")
53 {
54 return true;
55 }
56 return false;
57 }
58}
static bool TryGetSwitch(string switchName, out bool isEnabled)
Definition AppContext.cs:74
static bool GetSwitchDefaultValue(string switchName)
static bool GetCachedSwitchValue(string switchName, ref int cachedSwitchValue)
static bool GetCachedSwitchValueInternal(string switchName, ref int cachedSwitchValue)