< Summary

Information
Class: ArturRios.Configuration.Providers.SettingsProvider
Assembly: ArturRios.Configuration
File(s): D:\Repositories\dotnet-configuration\src\Providers\SettingsProvider.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 59
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 5
Fully covered methods: 2
Total methods: 5
Method coverage: 100%
Full method coverage: 40%

Metrics

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

File(s)

D:\Repositories\dotnet-configuration\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>
 814public class SettingsProvider(IConfiguration configuration) : IConfigurationProvider
 15{
 16    /// <summary>
 17    /// Gets a boolean value for the given configuration key.
 18    /// </summary>
 19    /// <param name="key">The configuration key.</param>
 20    /// <returns>The parsed boolean value, or <c>null</c> if not found or unparseable.</returns>
 21    public bool? GetBool(string key)
 422    {
 423        var value = configuration[key];
 24
 425        return value.ParseToBoolOrDefault();
 426    }
 27
 28    /// <summary>
 29    /// Gets an integer value for the given configuration key.
 30    /// </summary>
 31    /// <param name="key">The configuration key.</param>
 32    /// <returns>The parsed integer value, or <c>null</c> if not found or unparseable.</returns>
 33    public int? GetInt(string key)
 334    {
 335        var value = configuration[key];
 36
 337        return value.ParseToIntOrDefault();
 338    }
 39
 40    /// <summary>
 41    /// Gets the raw string value for the given configuration key.
 42    /// </summary>
 43    /// <param name="key">The configuration key.</param>
 44    /// <returns>The string value, or <c>null</c> if not found.</returns>
 245    public string? GetString(string key) => configuration[key];
 46
 47    /// <summary>
 48    /// Gets a deserialized object of type <typeparamref name="T"/> for the given configuration key.
 49    /// </summary>
 50    /// <typeparam name="T">The target type to deserialize to.</typeparam>
 51    /// <param name="key">The configuration key.</param>
 52    /// <returns>The deserialized object instance, or <c>null</c> if not found or unparseable.</returns>
 53    public T? GetObject<T>(string key) where T : class
 354    {
 355        var value = configuration[key];
 56
 357        return value.ParseToObjectOrDefault<T>();
 358    }
 59}