< Summary - PropertyGridHelpers Code Coverage

Information
Class: PropertyGridHelpers.Support.SubstringBasedBaseNameExtractor
Assembly: PropertyGridHelpers
File(s): c:\agent\_work\9\s\Code\PropertyGridHelpers\Support\SubstringBasedBaseNameExtractor.cs
Tag: PropertyGridHelpers Build_2025.7.15.1_#485
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 60
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBlocks covered Blocks not covered
ExtractBaseNames(...)260
ExtractBaseNames(...)250

File(s)

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

#LineLine coverage
 1#if NET35_OR_GREATER
 2
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6
 7namespace PropertyGridHelpers.Support
 8{
 9    /// <summary>
 10    /// Provides logic to extract base names from resource names, removing a specified assembly prefix and the
 11    /// standard <c>.resources</c> extension.
 12    /// </summary>
 13    /// <remarks>
 14    /// This implementation uses<see cref = "string.Substring(int, int)" /> for compatibility with frameworks
 15    /// prior to.NET 8, and is functionally equivalent to the range-based extractor defined for .NET 8 and higher.
 16    /// </remarks>
 17    /// <seealso cref="IResourceBaseNameExtractor"/>
 18    internal class SubstringBasedBaseNameExtractor : IResourceBaseNameExtractor
 19    {
 20        /// <summary>
 21        /// Extracts base names from the specified resource names, removing the standard <c>.resources</c> extension
 22        /// and stripping the provided assembly prefix if present.
 23        /// </summary>
 24        /// <param name="assemblyPrefix">
 25        /// The assembly prefix to remove from the beginning of resource names (e.g., the default namespace of the
 26        /// assembly). If the base name starts with this prefix, it will be removed along with any subsequent dot
 27        /// separator.
 28        /// </param>
 29        /// <param name="resourceNames">
 30        /// The full resource names to process, typically retrieved via <see cref="System.Reflection.Assembly.GetManifes
 31        /// </param>
 32        /// <returns>
 33        /// An ordered list of distinct base names with the <c>.resources</c> extension and the assembly prefix removed.
 34        /// </returns>
 35        public IList<string> ExtractBaseNames(string assemblyPrefix, string[] resourceNames)
 836        {
 37            const string resourceExtension = ".resources";
 1638            var resourceExtensionLength = resourceExtension.Length;
 1639            var baseNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
 40
 1641            foreach (var name in resourceNames)
 842            {
 1643                if (name.EndsWith(resourceExtension, StringComparison.OrdinalIgnoreCase))
 844                {
 1645                    var baseName = name.Substring(0, name.Length - resourceExtensionLength);
 46
 1647                    if (baseName.StartsWith(assemblyPrefix, StringComparison.OrdinalIgnoreCase))
 1648                        baseName = baseName.Substring(assemblyPrefix.Length).TrimStart('.');
 49
 1650                    _ = baseNames.Add(baseName);
 851                }
 52
 853            }
 54
 1655            return baseNames.OrderBy(x => x, StringComparer.OrdinalIgnoreCase).ToList();
 856        }
 57    }
 58}
 59
 60#endif