< Summary

Information
Class: MyNet.Fakers.Localization.ResourceDatasetLoader
Assembly: MyNet.Fakers
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Fakers/Localization/ResourceDatasetLoader.cs
Tag: 342_31701152804
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 55
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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
LoadList(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Fakers/Localization/ResourceDatasetLoader.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ResourceDatasetLoader.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Concurrent;
 9using System.Collections.Immutable;
 10using System.Globalization;
 11using System.Resources;
 12
 13namespace MyNet.Fakers.Localization;
 14
 15/// <summary>
 16/// Helper class for loading and caching resource datasets from semicolon-separated strings.
 17/// </summary>
 18internal static class ResourceDatasetLoader
 19{
 320    private static readonly ConcurrentDictionary<ResourceKey, ImmutableArray<string>> Cache = [];
 21
 22    /// <summary>
 23    /// Loads a localized string list from a RESX resource.
 24    /// </summary>
 25    /// <param name="resourceManager">The resource manager to load from.</param>
 26    /// <param name="key">The resource key.</param>
 27    /// <param name="culture">The target culture.</param>
 28    /// <returns>A cached read-only string list.</returns>
 29    public static ImmutableArray<string> LoadList(ResourceManager resourceManager, string key, CultureInfo culture)
 30    {
 7831        ArgumentNullException.ThrowIfNull(resourceManager);
 7832        ArgumentNullException.ThrowIfNull(key);
 7833        ArgumentNullException.ThrowIfNull(culture);
 34
 7835        var cacheKey = new ResourceKey(resourceManager, key, culture.Name);
 36
 7837        return Cache.GetOrAdd(cacheKey, static x =>
 7838        {
 7839            var value = x.ResourceManager.GetString(x.Key, CultureInfo.GetCultureInfo(x.Culture));
 7840
 7841            return string.IsNullOrWhiteSpace(value)
 7842                ? []
 7843                : [..value.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)];
 7844        });
 45    }
 46
 47    /// <summary>
 48    /// Represents a unique key for caching resource datasets, based on the resource type, key, and culture.
 49    /// </summary>
 50    /// <param name="ResourceManager">The resource manager.</param>
 51    /// <param name="Key">The resource key.</param>
 52    /// <param name="Culture">The target culture.</param>
 53    private sealed record ResourceKey(ResourceManager ResourceManager, string Key, string Culture);
 54}
 55