< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 37
Coverable lines: 37
Total lines: 101
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 24
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: 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
 20        {
 21            // The cached switch value has 3 states: 0 - unknown, 1 - true, -1 - false
 22            if (cachedSwitchValue < 0) return false;
 23            if (cachedSwitchValue > 0) return true;
 24
 25            return GetCachedSwitchValueInternal(switchName, null, ref cachedSwitchValue, defaultValue);
 26        }
 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.Http/src/System/Net/Http/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.Runtime.CompilerServices;
 5
 6namespace System
 7{
 8    internal static partial class LocalAppContextSwitches
 9    {
 10        private static int s_usePortInSpn;
 11        internal static bool UsePortInSpn
 12        {
 13            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 014            get => GetCachedSwitchValue("System.Net.Http.UsePortInSpn", "DOTNET_SYSTEM_NET_HTTP_USEPORTINSPN", ref s_use
 15        }
 16    }
 17}
 18