Merge pull request #3389 from lambdageek/bug-43099
[mono.git] / mcs / class / referencesource / System.ComponentModel.DataAnnotations / DataAnnotations / LocalAppContextSwitches.cs
1 // <copyright>
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 // </copyright>
4 namespace System.ComponentModel.DataAnnotations {
5     using System;
6     using System.Runtime.CompilerServices;
7
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;
15
16         public static bool UseLegacyRegExTimeout {
17             [MethodImpl(MethodImplOptions.AggressiveInlining)]
18             get {
19                 return LocalAppContext.GetCachedSwitchValue(UseLegacyRegExTimeoutString, ref useLegacyRegExTimeout);
20             }
21         }
22
23         public static void SetDefaultsLessOrEqual_46() {
24 #pragma warning disable BCL0012 //disable warning about AppContextDefaults not following the recommended pattern
25             // Define the switches that should be true for 4.6 or less, false for 4.6.1+.
26             LocalAppContext.DefineSwitchDefault(UseLegacyRegExTimeoutString, true);
27 #pragma warning restore BCL0012
28         }
29     }
30 }