blob: aea1353937df89f1bbbe251095cc113eea4dcc4c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Tango.Settings
{
/// <summary>
/// Represents a settings object base class.
/// </summary>
public abstract class SettingsBase : INotifyPropertyChanged
{
internal Action SaveAction { get; set; }
/// <summary>
/// Saves settings.
/// </summary>
/// <exception cref="System.InvalidOperationException">This settings instance is not registered with any settings manager.</exception>
public virtual void Save()
{
if (SaveAction == null)
{
throw new InvalidOperationException("This settings instance is not registered with any settings manager.");
}
SaveAction();
}
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Raises the property changed event.
/// </summary>
/// <param name="propName">Name of the property.</param>
protected virtual void RaisePropertyChanged(String propName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
/// <summary>
/// Raises the property changed event.
/// </summary>
/// <param name="propName">Name of the property.</param>
protected virtual void RaisePropertyChangedAuto([CallerMemberName] string caller = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(caller));
}
}
}
|