< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 46
Coverable lines: 46
Total lines: 166
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 28
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
File 1: GetCachedSwitchValue(...)0%440%
File 1: GetCachedSwitchValue(...)0%440%
File 1: GetCachedSwitchValueInternal(...)0%10100%
File 1: TryGetBooleanEnvironmentVariable(...)0%10100%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/Common/src/System/LocalAppContextSwitches.Common.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Runtime.CompilerServices;
 5
 6namespace System
 7{
 8    // Helper method for local caching of compatibility quirks. Keep this lean and simple - this file is included into
 9    // every framework assembly that implements any compatibility quirks.
 10    internal static partial class LocalAppContextSwitches
 11    {
 12        // Returns value of given switch using provided cache.
 13        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 14        internal static bool GetSwitchValue(string switchName, ref bool switchValue) =>
 15            AppContext.TryGetSwitch(switchName, out switchValue);
 16
 17        // Returns value of given switch using provided cache.
 18        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 19        internal static bool GetCachedSwitchValue(string switchName, ref int cachedSwitchValue, bool defaultValue = fals
 020        {
 21            // The cached switch value has 3 states: 0 - unknown, 1 - true, -1 - false
 022            if (cachedSwitchValue < 0) return false;
 023            if (cachedSwitchValue > 0) return true;
 24
 025            return GetCachedSwitchValueInternal(switchName, null, ref cachedSwitchValue, defaultValue);
 026        }
 27
 28        // Returns value of given switch or environment variable using provided cache.
 29        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 30        internal static bool GetCachedSwitchValue(string switchName, string? envVariable, ref int cachedSwitchValue, boo
 031        {
 32            // The cached switch value has 3 states: 0 - unknown, 1 - true, -1 - false
 033            if (cachedSwitchValue < 0) return false;
 034            if (cachedSwitchValue > 0) return true;
 35
 036            return GetCachedSwitchValueInternal(switchName, envVariable, ref cachedSwitchValue, defaultValue);
 037        }
 38
 39        private static bool GetCachedSwitchValueInternal(string switchName, string? envVariable, ref int cachedSwitchVal
 040        {
 041            if (!AppContext.TryGetSwitch(switchName, out bool isSwitchEnabled))
 042            {
 043                if (envVariable == null || !TryGetBooleanEnvironmentVariable(envVariable, out isSwitchEnabled))
 044                {
 045                    isSwitchEnabled = defaultValue;
 046                }
 047            }
 48
 049            AppContext.TryGetSwitch("TestSwitch.LocalAppContext.DisableCaching", out bool disableCaching);
 050            if (!disableCaching)
 051            {
 052                cachedSwitchValue = isSwitchEnabled ? 1 /*true*/ : -1 /*false*/;
 053            }
 54
 055            return isSwitchEnabled;
 056        }
 57
 58        private static bool TryGetBooleanEnvironmentVariable(string envVariable, out bool value)
 059        {
 060            if (Environment.GetEnvironmentVariable(envVariable) is string str)
 061            {
 062                if (str == "1" || string.Equals(str, bool.TrueString, StringComparison.OrdinalIgnoreCase))
 063                {
 064                    value = true;
 065                    return true;
 66                }
 67
 068                if (str == "0" || string.Equals(str, bool.FalseString, StringComparison.OrdinalIgnoreCase))
 069                {
 070                    value = false;
 071                    return true;
 72                }
 73
 074                value = false;
 075                return false;
 76            }
 77
 078            value = false;
 079            return false;
 080        }
 81    }
 82}
 83

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Security/src/System/Net/Security/LocalAppContextSwitches.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics.CodeAnalysis;
 5using System.Runtime.CompilerServices;
 6using System.Runtime.InteropServices;
 7
 8namespace System
 9{
 10    internal static partial class LocalAppContextSwitches
 11    {
 12        private static int s_disableTlsResume;
 13        internal static bool DisableTlsResume
 14        {
 15            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 016            get => GetCachedSwitchValue("System.Net.Security.DisableTlsResume", "DOTNET_SYSTEM_NET_SECURITY_DISABLETLSRE
 17        }
 18
 19        // By default the peer certificate is not re-validated on a resumed (abbreviated) TLS
 20        // handshake, matching the behavior of common TLS stacks (e.g. OpenSSL, SChannel) that
 21        // do not re-run certificate verification when a session is resumed. This optimization
 22        // only applies on platforms where session resumption can be detected (currently Windows
 23        // and Linux); elsewhere the peer certificate is always re-validated. Enabling this
 24        // switch restores the previous behavior of re-validating the peer certificate (running
 25        // the chain build and the user validation callback) on every successful resumption.
 26        private static int s_revalidateCertificateOnTlsResume;
 27        internal static bool RevalidateCertificateOnTlsResume
 28        {
 29            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 030            get => GetCachedSwitchValue("System.Net.Security.RevalidateCertificateOnTlsResume", "DOTNET_SYSTEM_NET_SECUR
 31        }
 32
 33        private static int s_captureClientHello;
 34        internal static bool CaptureClientHello
 35        {
 36            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 37            get => GetCachedSwitchValue("System.Net.Security.CaptureClientHello", "DOTNET_SYSTEM_NET_SECURITY_CAPTURECLI
 38        }
 39
 40        private static int s_enableServerAiaDownloads;
 41        internal static bool EnableServerAiaDownloads
 42        {
 43            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 044            get => GetCachedSwitchValue("System.Net.Security.EnableServerAiaDownloads", "DOTNET_SYSTEM_NET_SECURITY_ENAB
 45        }
 46
 47        private static int s_enableOcspStapling;
 48        internal static bool EnableOcspStapling
 49        {
 50            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 051            get => GetCachedSwitchValue("System.Net.Security.EnableServerOcspStaplingFromOnlyCertificateOnLinux", ref s_
 52        }
 53
 54        private static int s_useLegacySslStreamHandshake;
 55        internal static bool UseLegacySslStreamHandshake
 56        {
 57            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 058            get => GetCachedSwitchValue("System.Net.Security.UseLegacySslStreamHandshake", "DOTNET_SYSTEM_NET_SECURITY_U
 59        }
 60
 61#if !TARGET_WINDOWS
 62        private static int s_useManagedNtlm;
 63        [FeatureSwitchDefinition("System.Net.Security.UseManagedNtlm")]
 64        internal static bool UseManagedNtlm
 65        {
 66            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 67            get => GetCachedSwitchValue("System.Net.Security.UseManagedNtlm", ref s_useManagedNtlm,
 68                defaultValue: OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst() ||
 69                (OperatingSystem.IsLinux() && RuntimeInformation.RuntimeIdentifier.StartsWith("linux-bionic-", StringCom
 70        }
 71#endif
 72
 73#if TARGET_APPLE
 74        private static int s_useNetworkFramework;
 75        internal static bool UseNetworkFramework
 76        {
 77            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 78            get => GetCachedSwitchValue("System.Net.Security.UseNetworkFramework", "DOTNET_SYSTEM_NET_SECURITY_USENETWOR
 79        }
 80#endif
 81    }
 82}
 83