< Summary

Information
Class: ArturRios.Configuration.Providers.SettingsProvider
Assembly: ArturRios.Configuration
File(s): /home/ci/agent/workspace/dotnet-configuration-docs_main/app/src/Providers/SettingsProvider.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 70
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage
100%
Covered methods: 5
Fully covered methods: 5
Total methods: 5
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
GetBool(...)100%11100%
GetInt(...)100%11100%
GetString(...)100%11100%
GetObject(...)100%11100%

File(s)

/home/ci/agent/workspace/dotnet-configuration-docs_main/app/src/Providers/SettingsProvider.cs

#LineLine coverage
 1using ArturRios.Extensions;
 2using Microsoft.Extensions.Configuration;
 3
 4namespace ArturRios.Configuration.Providers;
 5
 6using IConfigurationProvider = Interfaces.IConfigurationProvider;
 7
 8/// <summary>
 9/// Provides configuration values from an <see cref="IConfiguration"/> source (e.g., appsettings.json, environment varia
 10/// </summary>
 11/// <remarks>
 12/// Values are retrieved as strings and parsed using helper extension methods into booleans, integers, or deserialized o
 13/// </remarks>
 14/// <param name="configuration">The configuration to read from.</param>
 15/// <exception cref="ArgumentNullException"><paramref name="configuration"/> is <c>null</c>.</exception>
 916public class SettingsProvider(IConfiguration configuration) : IConfigurationProvider
 17{
 1018    private readonly IConfiguration _configuration =
 1019        configuration ?? throw new ArgumentNullException(nameof(configuration));
 20
 21    /// <summary>
 22    /// Gets a boolean value for the given configuration key.
 23    /// </summary>
 24    /// <param name="key">The configuration key.</param>
 25    /// <returns>The parsed boolean value, or <c>null</c> if not found or unparseable.</returns>
 26    public bool? GetBool(string key)
 27    {
 428        var value = _configuration[key];
 29
 430        return value.ParseToBoolOrDefault();
 31    }
 32
 33    /// <summary>
 34    /// Gets an integer value for the given configuration key.
 35    /// </summary>
 36    /// <param name="key">The configuration key.</param>
 37    /// <returns>The parsed integer value, or <c>null</c> if not found or unparseable.</returns>
 38    public int? GetInt(string key)
 39    {
 340        var value = _configuration[key];
 41
 342        return value.ParseToIntOrDefault();
 43    }
 44
 45    /// <summary>
 46    /// Gets the raw string value for the given configuration key.
 47    /// </summary>
 48    /// <param name="key">The configuration key.</param>
 49    /// <returns>The string value, or <c>null</c> if not found.</returns>
 350    public string? GetString(string key) => _configuration[key];
 51
 52    /// <summary>
 53    /// Gets a deserialized object of type <typeparamref name="T"/> for the given configuration key.
 54    /// </summary>
 55    /// <typeparam name="T">The target type to deserialize to.</typeparam>
 56    /// <param name="key">The configuration key.</param>
 57    /// <returns>The deserialized object instance, or <c>null</c> if not found or unparseable.</returns>
 58    /// <remarks>
 59    /// The value stored under <paramref name="key"/> must itself be a JSON string. A section such as
 60    /// <c>"Database": { "Host": "..." }</c> in an appsettings file has no value of its own — its children do —
 61    /// so it reads as <c>null</c>; bind a section with <c>configuration.GetSection(key).Get&lt;T&gt;()</c> from
 62    /// Microsoft.Extensions.Configuration.Binder instead.
 63    /// </remarks>
 64    public T? GetObject<T>(string key) where T : class
 65    {
 466        var value = _configuration[key];
 67
 468        return value.ParseToObjectOrDefault<T>();
 69    }
 70}