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