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{
7 private static int s_enableUnsafeUTF7Encoding;
8
10
12
14
16
17 private static int s_serializationGuard;
18
19 private static int s_showILOffset;
20
21 public static bool EnableUnsafeUTF7Encoding
22 {
23 [MethodImpl(MethodImplOptions.AggressiveInlining)]
24 get
25 {
26 return GetCachedSwitchValue("System.Text.Encoding.EnableUnsafeUTF7Encoding", ref s_enableUnsafeUTF7Encoding);
27 }
28 }
29
31 {
32 [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 get
34 {
35 return GetCachedSwitchValue("Switch.System.Globalization.EnforceJapaneseEraYearRanges", ref s_enforceJapaneseEraYearRanges);
36 }
37 }
38
40 {
41 [MethodImpl(MethodImplOptions.AggressiveInlining)]
42 get
43 {
44 return GetCachedSwitchValue("Switch.System.Globalization.FormatJapaneseFirstYearAsANumber", ref s_formatJapaneseFirstYearAsANumber);
45 }
46 }
47
49 {
50 [MethodImpl(MethodImplOptions.AggressiveInlining)]
51 get
52 {
53 return GetCachedSwitchValue("Switch.System.Globalization.EnforceLegacyJapaneseDateParsing", ref s_enforceLegacyJapaneseDateParsing);
54 }
55 }
56
58 {
59 [MethodImpl(MethodImplOptions.AggressiveInlining)]
60 get
61 {
62 return GetCachedSwitchValue("Switch.System.Diagnostics.EventSource.PreserveEventListnerObjectIdentity", ref s_preserveEventListnerObjectIdentity);
63 }
64 }
65
66 public static bool SerializationGuard
67 {
68 [MethodImpl(MethodImplOptions.AggressiveInlining)]
69 get
70 {
71 return GetCachedSwitchValue("Switch.System.Runtime.Serialization.SerializationGuard", ref s_serializationGuard);
72 }
73 }
74
75 public static bool ShowILOffsets
76 {
77 [MethodImpl(MethodImplOptions.AggressiveInlining)]
78 get
79 {
81 }
82 }
83
84 private static bool GetDefaultShowILOffsetSetting()
85 {
86 if (s_showILOffset < 0)
87 {
88 return false;
89 }
90 if (s_showILOffset > 0)
91 {
92 return true;
93 }
94 bool booleanConfig = AppContextConfigHelper.GetBooleanConfig("Switch.System.Diagnostics.StackTrace.ShowILOffsets", defaultValue: false);
95 s_showILOffset = (booleanConfig ? 1 : (-1));
96 return booleanConfig;
97 }
98
99 [MethodImpl(MethodImplOptions.AggressiveInlining)]
100 internal static bool GetCachedSwitchValue(string switchName, ref int cachedSwitchValue)
101 {
102 if (cachedSwitchValue < 0)
103 {
104 return false;
105 }
106 if (cachedSwitchValue > 0)
107 {
108 return true;
109 }
110 return GetCachedSwitchValueInternal(switchName, ref cachedSwitchValue);
111 }
112
113 private static bool GetCachedSwitchValueInternal(string switchName, ref int cachedSwitchValue)
114 {
115 if (!AppContext.TryGetSwitch(switchName, out var isEnabled))
116 {
117 isEnabled = GetSwitchDefaultValue(switchName);
118 }
119 AppContext.TryGetSwitch("TestSwitch.LocalAppContext.DisableCaching", out var isEnabled2);
120 if (!isEnabled2)
121 {
122 cachedSwitchValue = (isEnabled ? 1 : (-1));
123 }
124 return isEnabled;
125 }
126
127 private static bool GetSwitchDefaultValue(string switchName)
128 {
129 if (switchName == "Switch.System.Runtime.Serialization.SerializationGuard")
130 {
131 return true;
132 }
133 if (switchName == "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization")
134 {
135 return true;
136 }
137 return false;
138 }
139}
static bool GetBooleanConfig(string configName, bool defaultValue)
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)