Update Reference Sources to .NET Framework 4.6.1
[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             // Define the switches that should be true for 4.6 or less, false for 4.6.1+.
25             LocalAppContext.DefineSwitchDefault(UseLegacyRegExTimeoutString, true);
26         }
27     }
28 }