Merge pull request #3389 from lambdageek/bug-43099
[mono.git] / mcs / class / referencesource / System.IdentityModel / System / IdentityModel / LocalAppContextSwitches.cs
1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------
4
5 namespace System.IdentityModel
6 {
7     using System;
8     using System.Runtime.CompilerServices;
9
10     // When adding a quirk, name it such that false is new behavior and true is old behavior.
11     // You are opting IN to old behavior. The new behavior is default.
12     // For example, we want to enable the functionality to explicitly add a connection close header
13     // in 4.6 and above. So we set DisableExplicitConnectionCloseHeader to true if running 4.5.2 or less.
14     internal static class LocalAppContextSwitches
15     {
16         private const string EnableCachedEmptyDefaultAuthorizationContextString = "Switch.System.IdentityModel.EnableCachedEmptyDefaultAuthorizationContext";
17         private const string DisableMultipleDNSEntriesInSANCertificateString = "Switch.System.IdentityModel.DisableMultipleDNSEntriesInSANCertificate";
18         private const string DisableUpdatingRsaProviderTypeString = "Switch.System.IdentityModel.DisableUpdatingRsaProviderType";
19
20         private static int enableCachedEmptyDefaultAuthorizationContext;
21         private static int disableMultipleDNSEntriesInSANCertificate;
22         private static int disableUpdatingRsaProviderType;
23
24         public static bool EnableCachedEmptyDefaultAuthorizationContext
25         {
26             [MethodImpl(MethodImplOptions.AggressiveInlining)]
27             get
28             {
29                 return LocalAppContext.GetCachedSwitchValue(EnableCachedEmptyDefaultAuthorizationContextString, ref enableCachedEmptyDefaultAuthorizationContext);
30             }
31         }
32
33         public static bool DisableMultipleDNSEntriesInSANCertificate
34         {
35             [MethodImpl(MethodImplOptions.AggressiveInlining)]
36             get
37             {
38                 return LocalAppContext.GetCachedSwitchValue(DisableMultipleDNSEntriesInSANCertificateString, ref disableMultipleDNSEntriesInSANCertificate);
39             }
40         }
41
42         public static bool DisableUpdatingRsaProviderType
43         {
44             [MethodImpl(MethodImplOptions.AggressiveInlining)]
45             get
46             {
47                 return LocalAppContext.GetCachedSwitchValue(DisableUpdatingRsaProviderTypeString, ref disableUpdatingRsaProviderType);
48             }
49         }
50
51         public static void SetDefaultsLessOrEqual_452()
52         {
53 #pragma warning disable BCL0012
54             // Define the switches that should be true for 4.5.2 or less, false for 4.6+.
55             LocalAppContext.DefineSwitchDefault(EnableCachedEmptyDefaultAuthorizationContextString, true);
56 #pragma warning restore BCL0012
57         }
58
59         public static void SetDefaultsLessOrEqual_46()
60         {
61 #pragma warning disable BCL0012
62             // Define the switches that should be true for 4.6 or less, false for 4.6.1+.
63             LocalAppContext.DefineSwitchDefault(DisableMultipleDNSEntriesInSANCertificateString, true);
64 #pragma warning restore BCL0012
65         }
66     }
67 }