-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropertyNotifier.cs
40 lines (33 loc) · 1.47 KB
/
PropertyNotifier.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json.Serialization;
namespace OpenSkillBot {
public abstract class PropertyNotifier : INotifyPropertyChanged {
/// <summary>
/// Sets the value of a property such that it can be binded to the view.
/// </summary>
/// <typeparam name="T">The type of the field to set.</typeparam>
/// <param name="reference">The reference of the field to set.</param>
/// <param name="value">The value to set.</param>
/// <param name="propertyName">The property name of the calling member.</param>
public void Set<T>(ref T reference, T value, [CallerMemberName] string propertyName = null) {
// set the reference value.
reference = value;
// call PropertyChanged on the property.
OnPropertyChanged(propertyName);
}
#region INotifyPropertyChanged members
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Invokes PropertyChanged on a given propertyName.
/// </summary>
/// <param name="propertyName">The name of the property on which to call the PropertyChanged event on.</param>
public void OnPropertyChanged(string propertyName) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}