< Summary

Information
Class: MyNet.UI.Services.PreferencesService
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Services/PreferencesService.cs
Tag: 323_28699572109
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 61
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Reload()100%210%
Reset()100%210%
Save()100%210%
Dispose(...)0%2040%
Dispose()100%210%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Services/PreferencesService.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="PreferencesService.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using System.Linq;
 10using MyNet.Collections;
 11
 12namespace MyNet.UI.Services;
 13
 14/// <summary>
 15/// Service that manages persistent user preferences by delegating to multiple settings groups.
 16/// Implements <see cref="IPersistentPreferencesService"/> and <see cref="IDisposable"/>.
 17/// </summary>
 18/// <remarks>
 19/// Initializes a new instance of the <see cref="PreferencesService"/> class.
 20/// </remarks>
 21/// <param name="groups">The collection of settings groups to manage.</param>
 22public class PreferencesService(IEnumerable<IPersistentSettingsService> groups) : IPersistentPreferencesService, IDispos
 23{
 024    private readonly IList<IPersistentSettingsService> _groups = [.. groups];
 25    private bool _disposedValue;
 26
 27    /// <inheritdoc/>
 028    public void Reload() => _groups.ForEach(x => x.Reload());
 29
 30    /// <inheritdoc/>
 031    public void Reset() => _groups.ForEach(x => x.Reset());
 32
 33    /// <inheritdoc/>
 034    public void Save() => _groups.ForEach(x => x.Save());
 35
 36    /// <summary>
 37    /// Releases resources used by the service and disposes all disposable settings groups.
 38    /// </summary>
 39    /// <param name="disposing">Indicates whether the method is called from Dispose.</param>
 40    protected virtual void Dispose(bool disposing)
 41    {
 042        if (_disposedValue)
 043            return;
 044        if (disposing)
 45        {
 046            _groups.OfType<IDisposable>().ForEach(x => x.Dispose());
 47        }
 48
 049        _disposedValue = true;
 050    }
 51
 52    /// <summary>
 53    /// Disposes the service and its managed resources.
 54    /// </summary>
 55    public void Dispose()
 56    {
 057        Dispose(disposing: true);
 058        GC.SuppressFinalize(this);
 059    }
 60}
 61