| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="AutoSaveFeature.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | |
| | | 9 | | namespace MyNet.IO.AutoSave; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Represents the auto-save feature, allowing to enable or disable it and notifying about changes in its state. |
| | | 13 | | /// </summary> |
| | | 14 | | public sealed class AutoSaveFeature : IAutoSaveFeature |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets a value indicating whether the auto-save feature is currently enabled. |
| | | 18 | | /// </summary> |
| | | 19 | | public bool IsEnabled { get; private set; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Occurs when the state of the auto-save feature changes. The event handler receives a boolean value indicating th |
| | | 23 | | /// </summary> |
| | | 24 | | public event EventHandler<AutoSaveEnabledChangedEventArgs>? Changed; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Enables the auto-save feature. If the feature is already enabled, this method does nothing. If the state changes |
| | | 28 | | /// </summary> |
| | 6 | 29 | | public void Enable() => Set(true); |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Disables the auto-save feature. If the feature is already disabled, this method does nothing. If the state chang |
| | | 33 | | /// </summary> |
| | 3 | 34 | | public void Disable() => Set(false); |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Sets the state of the auto-save feature to the specified value. If the new value is the same as the current stat |
| | | 38 | | /// </summary> |
| | | 39 | | /// <param name="value">The new state of the auto-save feature.</param> |
| | | 40 | | private void Set(bool value) |
| | | 41 | | { |
| | 9 | 42 | | if (IsEnabled == value) |
| | 3 | 43 | | return; |
| | | 44 | | |
| | 6 | 45 | | IsEnabled = value; |
| | 6 | 46 | | Changed?.Invoke(this, new(value)); |
| | 6 | 47 | | } |
| | | 48 | | } |
| | | 49 | | |