Skip to content

Commit

Permalink
Make GlobalizationMode code consistent (#55039)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Toub <[email protected]>
  • Loading branch information
tarekgh and stephentoub authored Jul 1, 2021
1 parent e3dd985 commit 9c060fe
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,17 @@ internal static partial class GlobalizationMode
// split from GlobalizationMode so the whole class can be trimmed when Invariant=true.
private static partial class Settings
{
internal static bool Invariant { get; } = GetInvariantSwitchValue();
internal static readonly bool PredefinedCulturesOnly = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", Invariant);
internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT");
internal static bool PredefinedCulturesOnly { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", Invariant);
}

// Note: Invariant=true and Invariant=false are substituted at different levels in the ILLink.Substitutions file.
// This allows for the whole Settings nested class to be trimmed when Invariant=true, and allows for the Settings
// static cctor (on Unix) to be preserved when Invariant=false.
internal static bool Invariant => Settings.Invariant;

internal static bool PredefinedCulturesOnly => Settings.PredefinedCulturesOnly;

private static bool GetInvariantSwitchValue() =>
AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT");

private static bool TryGetAppLocalIcuSwitchValue([NotNullWhen(true)] out string? value) =>
TryGetStringValue("System.Globalization.AppLocalIcu", "DOTNET_SYSTEM_GLOBALIZATION_APPLOCALICU", out value);

private static bool TryGetStringValue(string switchName, string envVariable, [NotNullWhen(true)] out string? value)
{
value = AppContext.GetData(switchName) as string;
Expand Down

0 comments on commit 9c060fe

Please sign in to comment.