-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPropertyChangedBase.cs
39 lines (32 loc) · 1.15 KB
/
PropertyChangedBase.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
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace WwtbamOld;
public abstract class PropertyChangedBase : INotifyPropertyChanged
{
protected T RaiseAndSetIfChanged<T>(ref T backingField, T newValue, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(backingField, newValue))
return newValue;
backingField = newValue;
RaisePropertyChanged(propertyName);
return newValue;
}
public virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler propertyChanged = PropertyChanged;
if (propertyChanged is null)
return;
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
public virtual void UpdateAllProperties()
{
foreach (PropertyInfo propertyInfo in GetType().GetProperties())
{
if (propertyInfo.CanRead)
RaisePropertyChanged(propertyInfo.Name);
}
}
}