Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/System.Private.CoreLib/src/System/AppContextSwitches.cs')
-rw-r--r--src/System.Private.CoreLib/src/System/AppContextSwitches.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/System.Private.CoreLib/src/System/AppContextSwitches.cs b/src/System.Private.CoreLib/src/System/AppContextSwitches.cs
new file mode 100644
index 000000000..f838871e8
--- /dev/null
+++ b/src/System.Private.CoreLib/src/System/AppContextSwitches.cs
@@ -0,0 +1,60 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.CompilerServices;
+
+namespace System
+{
+ internal static class AppContextSwitches
+ {
+ private static int _enforceJapaneseEraYearRanges;
+ public static bool EnforceJapaneseEraYearRanges
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
+ {
+ return GetCachedSwitchValue("Switch.System.Globalization.EnforceJapaneseEraYearRanges", ref _enforceJapaneseEraYearRanges);
+ }
+ }
+
+ //
+ // Implementation details
+ //
+
+ private static bool DisableCaching { get; set; }
+
+ static AppContextSwitches()
+ {
+ bool isEnabled;
+ if (AppContext.TryGetSwitch(@"TestSwitch.LocalAppContext.DisableCaching", out isEnabled))
+ {
+ DisableCaching = isEnabled;
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal static bool GetCachedSwitchValue(string switchName, ref int switchValue)
+ {
+ if (switchValue < 0) return false;
+ if (switchValue > 0) return true;
+
+ return GetCachedSwitchValueInternal(switchName, ref switchValue);
+ }
+
+ private static bool GetCachedSwitchValueInternal(string switchName, ref int switchValue)
+ {
+ bool isSwitchEnabled;
+ AppContext.TryGetSwitch(switchName, out isSwitchEnabled);
+
+ if (DisableCaching)
+ {
+ return isSwitchEnabled;
+ }
+
+ switchValue = isSwitchEnabled ? 1 /*true*/ : -1 /*false*/;
+ return isSwitchEnabled;
+ }
+ }
+}