< Summary

Information
Class: ProjectTemplate.Web.Extensions.ConfigurationListBinding
Assembly: ProjectTemplate.Web
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Extensions/ConfigurationListBinding.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 46
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ReplaceWithConfiguredValues(...)100%66100%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Extensions/ConfigurationListBinding.cs

#LineLine coverage
 1namespace ProjectTemplate.Web.Extensions;
 2
 3/// <summary>
 4/// Gives list options bound from configuration replace semantics instead of append semantics.
 5/// </summary>
 6/// <remarks>
 7/// The configuration binder adds configured entries to a list that already holds code defaults, so a configured list
 8/// could only ever extend the defaults and never remove one. A configured list replaces the defaults here instead.
 9/// Blank entries are ignored, which lets a higher-precedence configuration source remove an inherited entry by
 10/// overriding its index with an empty value. When the section has no entries, the code defaults are kept.
 11/// </remarks>
 12internal static class ConfigurationListBinding
 13{
 14    /// <summary>
 15    /// Replaces the contents of <paramref name="target"/> with the non-blank values configured in
 16    /// <paramref name="section"/>, when the section has any entries.
 17    /// </summary>
 18    /// <param name="target">The bound list to replace.</param>
 19    /// <param name="section">The configuration section that holds the list entries.</param>
 20    internal static void ReplaceWithConfiguredValues(List<string> target, IConfigurationSection section)
 21    {
 41622        ArgumentNullException.ThrowIfNull(target);
 41623        ArgumentNullException.ThrowIfNull(section);
 24
 41625        List<string> configuredValues = [];
 41626        bool hasConfiguredEntries = false;
 27
 451828        foreach (IConfigurationSection child in section.GetChildren())
 29        {
 184330            hasConfiguredEntries = true;
 31
 184332            if (!string.IsNullOrWhiteSpace(child.Value))
 33            {
 184034                configuredValues.Add(child.Value);
 35            }
 36        }
 37
 41638        if (!hasConfiguredEntries)
 39        {
 440            return;
 41        }
 42
 41243        target.Clear();
 41244        target.AddRange(configuredValues);
 41245    }
 46}