2 using Microsoft.Win32.SafeHandles;
9 internal static class AppContextDefaultValues
11 internal static readonly
string SwitchNoAsyncCurrentCulture =
"Switch.System.Globalization.NoAsyncCurrentCulture";
13 internal static readonly
string SwitchThrowExceptionIfDisposedCancellationTokenSource =
"Switch.System.Threading.ThrowExceptionIfDisposedCancellationTokenSource";
15 internal static readonly
string SwitchPreserveEventListnerObjectIdentity =
"Switch.System.Diagnostics.EventSource.PreserveEventListnerObjectIdentity";
17 internal static readonly
string SwitchUseLegacyPathHandling =
"Switch.System.IO.UseLegacyPathHandling";
19 internal static readonly
string SwitchBlockLongPaths =
"Switch.System.IO.BlockLongPaths";
21 internal static readonly
string SwitchDoNotAddrOfCspParentWindowHandle =
"Switch.System.Security.Cryptography.DoNotAddrOfCspParentWindowHandle";
23 internal static readonly
string SwitchSetActorAsReferenceWhenCopyingClaimsIdentity =
"Switch.System.Security.ClaimsIdentity.SetActorAsReferenceWhenCopyingClaimsIdentity";
25 private static volatile bool s_errorReadingRegistry;
27 public static void PopulateDefaultValues()
29 ParseTargetFrameworkName(out
string identifier, out
string profile, out
int version);
30 PopulateDefaultValuesPartial(identifier, profile, version);
33 private static void ParseTargetFrameworkName(out
string identifier, out
string profile, out
int version)
35 string targetFrameworkName =
AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName;
36 if (!TryParseFrameworkName(targetFrameworkName, out identifier, out version, out profile))
38 identifier =
".NETFramework";
40 profile =
string.Empty;
44 private static bool TryParseFrameworkName(
string frameworkName, out
string identifier, out
int version, out
string profile)
46 identifier = (profile =
string.Empty);
48 if (frameworkName ==
null || frameworkName.Length == 0)
52 string[] array = frameworkName.Split(
',');
54 if (array.Length < 2 || array.Length > 3)
58 identifier = array[0].Trim();
59 if (identifier.Length == 0)
65 for (
int i = 1; i < array.Length; i++)
67 string[] array2 = array[i].Split(
'=');
68 if (array2.Length != 2)
72 string text = array2[0].Trim();
73 string text2 = array2[1].Trim();
77 if (text2.Length > 0 && (text2[0] ==
'v' || text2[0] ==
'V'))
79 text2 = text2.Substring(1);
81 Version version2 =
new Version(text2);
82 version = version2.Major * 10000;
83 if (version2.Minor > 0)
85 version += version2.Minor * 100;
87 if (version2.Build > 0)
89 version += version2.Build;
98 if (!
string.IsNullOrEmpty(text2))
111 [SecuritySafeCritical]
112 private static void TryGetSwitchOverridePartial(
string switchName, ref
bool overrideFound, ref
bool overrideValue)
115 overrideFound =
false;
116 if (!s_errorReadingRegistry)
118 text = GetSwitchValueFromRegistry(switchName);
122 text = CompatibilitySwitch.GetValue(switchName);
124 if (text !=
null &&
bool.TryParse(text, out
bool result))
126 overrideValue = result;
127 overrideFound =
true;
131 private static void PopulateDefaultValuesPartial(
string platformIdentifier,
string profile,
int version)
133 if (!(platformIdentifier ==
".NETCore") && !(platformIdentifier ==
".NETFramework"))
135 if ((platformIdentifier ==
"WindowsPhone" || platformIdentifier ==
"WindowsPhoneApp") && version <= 80100)
137 AppContext.DefineSwitchDefault(SwitchNoAsyncCurrentCulture, isEnabled:
true);
138 AppContext.DefineSwitchDefault(SwitchThrowExceptionIfDisposedCancellationTokenSource, isEnabled:
true);
139 AppContext.DefineSwitchDefault(SwitchUseLegacyPathHandling, isEnabled:
true);
140 AppContext.DefineSwitchDefault(SwitchBlockLongPaths, isEnabled:
true);
141 AppContext.DefineSwitchDefault(SwitchDoNotAddrOfCspParentWindowHandle, isEnabled:
true);
146 if (version <= 40502)
148 AppContext.DefineSwitchDefault(SwitchNoAsyncCurrentCulture, isEnabled:
true);
149 AppContext.DefineSwitchDefault(SwitchThrowExceptionIfDisposedCancellationTokenSource, isEnabled:
true);
151 if (version <= 40601)
153 AppContext.DefineSwitchDefault(SwitchUseLegacyPathHandling, isEnabled:
true);
154 AppContext.DefineSwitchDefault(SwitchBlockLongPaths, isEnabled:
true);
155 AppContext.DefineSwitchDefault(SwitchSetActorAsReferenceWhenCopyingClaimsIdentity, isEnabled:
true);
157 if (version <= 40602)
159 AppContext.DefineSwitchDefault(SwitchDoNotAddrOfCspParentWindowHandle, isEnabled:
true);
162 PopulateOverrideValuesPartial();
165 [SecuritySafeCritical]
166 private static void PopulateOverrideValuesPartial()
168 string appContextOverridesInternalCall = CompatibilitySwitch.GetAppContextOverridesInternalCall();
169 if (
string.IsNullOrEmpty(appContextOverridesInternalCall))
178 for (
int i = 0; i <= appContextOverridesInternalCall.Length; i++)
180 if (i == appContextOverridesInternalCall.Length || appContextOverridesInternalCall[i] ==
';')
182 if ((flag && flag2) & flag3)
184 int startIndex = num + 1;
185 int length = num2 - num - 1;
186 string switchName = appContextOverridesInternalCall.Substring(startIndex, length);
187 int startIndex2 = num2 + 1;
188 int length2 = i - num2 - 1;
189 string value = appContextOverridesInternalCall.Substring(startIndex2, length2);
190 if (
bool.TryParse(value, out
bool result))
192 AppContext.DefineSwitchOverride(switchName, result);
196 flag2 = (flag3 = (flag =
false));
198 else if (appContextOverridesInternalCall[i] ==
'=')
217 public static bool TryGetSwitchOverride(
string switchName, out
bool overrideValue)
219 overrideValue =
false;
220 bool overrideFound =
false;
221 TryGetSwitchOverridePartial(switchName, ref overrideFound, ref overrideValue);
222 return overrideFound;
225 [SecuritySafeCritical]
226 private static string GetSwitchValueFromRegistry(
string switchName)
230 using (SafeRegistryHandle hKey =
new SafeRegistryHandle((IntPtr)(-2147483646), ownsHandle:
true))
232 SafeRegistryHandle hkResult =
null;
233 if (Win32Native.RegOpenKeyEx(hKey,
"SOFTWARE\\Microsoft\\.NETFramework\\AppContext", 0, 131097, out hkResult) == 0)
238 if (Win32Native.RegQueryValueEx(hkResult, switchName,
null, ref lpType, stringBuilder, ref lpcbData) == 0)
245 s_errorReadingRegistry =
true;
251 s_errorReadingRegistry =
true;
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
Finds or creates a T:System.AppDomain.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....