< Summary - PropertyGridHelpers Code Coverage

Information
Class: PropertyGridHelpers.Support.RangeBasedBaseNameExtractor
Assembly: PropertyGridHelpers
File(s): c:\agent\_work\9\s\Code\PropertyGridHelpers\Support\RangeBasedBaseNameExtractor.cs
Tag: PropertyGridHelpers Build_2025.7.15.1_#485
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 57
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

Coverage history

Coverage history 0 25 50 75 100

Metrics

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

File(s)

c:\agent\_work\9\s\Code\PropertyGridHelpers\Support\RangeBasedBaseNameExtractor.cs

#LineLine coverage
 1#if NET8_0_OR_GREATER
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5
 6namespace PropertyGridHelpers.Support
 7{
 8    /// <summary>
 9    /// Provides logic to extract base names from resource names, removing a specified assembly prefix and
 10    /// the standard <c>.resources</c> extension.
 11    /// </summary>
 12    /// <remarks>
 13    /// This implementation is useful when working with resource files that are embedded with fully qualified names,
 14    /// allowing you to obtain simpler base names for further processing.
 15    /// </remarks>
 16    /// <seealso cref="IResourceBaseNameExtractor"/>
 17    internal class RangeBasedBaseNameExtractor : IResourceBaseNameExtractor
 18    {
 19        /// <summary>
 20        /// Extracts base names from the specified resource names, removing the standard <c>.resources</c>
 21        /// extension and stripping the provided assembly prefix if present.
 22        /// </summary>
 23        /// <param name="assemblyPrefix">
 24        /// The assembly prefix to remove from the beginning of resource names (e.g., the default namespace
 25        /// of the assembly). If the base name starts with this prefix, it will be removed along with any
 26        /// subsequent dot separator.
 27        /// </param>
 28        /// <param name="resourceNames">
 29        /// The full resource names to process, typically retrieved via <see cref="System.Reflection.Assembly.GetManifes
 30        /// </param>
 31        /// <returns>
 32        /// An ordered list of distinct base names with the <c>.resources</c> extension and the assembly prefix removed.
 33        /// </returns>
 34        public IList<string> ExtractBaseNames(string assemblyPrefix, string[] resourceNames)
 1635        {
 36            const string resourceExtension = ".resources";
 1637            var resourceExtensionLength = resourceExtension.Length;
 1638            var baseNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
 39
 17640            foreach (var name in resourceNames)
 6441            {
 6442                if (name.EndsWith(resourceExtension, StringComparison.OrdinalIgnoreCase))
 4843                {
 4844                    var baseName = name[..^resourceExtensionLength];
 45
 4846                    if (baseName.StartsWith(assemblyPrefix, StringComparison.OrdinalIgnoreCase))
 4847                        baseName = baseName[assemblyPrefix.Length..].TrimStart('.');
 48
 4849                    _ = baseNames.Add(baseName);
 4850                }
 6451            }
 52
 6453            return [.. baseNames.OrderBy(x => x, StringComparer.OrdinalIgnoreCase)];
 1654        }
 55    }
 56}
 57#endif