2 // Copyright (c) Microsoft Corporation. All rights reserved.
4 namespace System.ComponentModel.DataAnnotations {
6 using System.Runtime.CompilerServices;
8 // When adding a quirk, name it such that false is new behavior and true is old behavior.
9 // You are opting IN to old behavior. The new behavior is default.
10 // For example, we don't want to use legacy regex timeout for RegularExpressionAttribute in 4.6.1+.
11 // So we set UseLegacyRegExTimeout to true if running 4.6 or less.
12 internal static class LocalAppContextSwitches {
13 private const string UseLegacyRegExTimeoutString = "Switch.System.ComponentModel.DataAnnotations.RegularExpressionAttribute.UseLegacyRegExTimeout";
14 private static int useLegacyRegExTimeout;
16 public static bool UseLegacyRegExTimeout {
17 [MethodImpl(MethodImplOptions.AggressiveInlining)]
19 return LocalAppContext.GetCachedSwitchValue(UseLegacyRegExTimeoutString, ref useLegacyRegExTimeout);
23 public static void SetDefaultsLessOrEqual_46() {
24 // Define the switches that should be true for 4.6 or less, false for 4.6.1+.
25 LocalAppContext.DefineSwitchDefault(UseLegacyRegExTimeoutString, true);