-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathWheelOptionsBase.cs
More file actions
43 lines (36 loc) · 1.44 KB
/
Copy pathWheelOptionsBase.cs
File metadata and controls
43 lines (36 loc) · 1.44 KB
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
using System.ComponentModel;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
namespace AcTools.WheelAngles {
public class WheelOptionsBase : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
private bool _loaded;
public void EnsureLoaded() {
if (!_loaded) {
_loaded = true;
_storage?.LoadValues(this);
}
}
private static IWheelSteerLockOptionsStorage _storage;
public static void SetStorage([CanBeNull] IWheelSteerLockOptionsStorage storage) {
_storage = storage;
}
protected bool Apply<T>(T value, ref T backendValue, [CallerMemberName] string propertyName = null,
params string[] linked) {
if (Equals(value, backendValue)) return false;
backendValue = value;
OnPropertyChanged(propertyName);
if (linked != null) {
for (var i = 0; i < linked.Length; i++) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(linked[i]));
}
}
return true;
}
[NotifyPropertyChangedInvocator]
protected void OnPropertyChanged([CallerMemberName] string propertyName = null) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
_storage?.StoreValues(this);
}
}
}