-
Notifications
You must be signed in to change notification settings - Fork 0
/
BindableBase.cs
56 lines (50 loc) · 1.97 KB
/
BindableBase.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Xamariners.Mvvm.Core
{
public abstract class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangingEventHandler PropertyChanging;
protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(storage, value))
return false;
storage = value;
this.OnPropertyChanging(propertyName);
this.RaisePropertyChanged(propertyName);
return true;
}
protected virtual bool SetProperty<T>(
ref T storage,
T value,
Action onPropertyChanging,
[CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(storage, value))
return false;
storage = value;
if (onPropertyChanging != null)
onPropertyChanging();
this.OnPropertyChanging(propertyName);
this.RaisePropertyChanged(propertyName);
return true;
}
protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if (propertyChanged == null)
return;
propertyChanged((object)this, new PropertyChangedEventArgs(propertyName));
}
protected virtual void OnPropertyChanging([CallerMemberName] string propertyName = null)
{
PropertyChangingEventHandler propertyChanging = this.PropertyChanging;
if (propertyChanging == null)
return;
propertyChanging((object)this, new PropertyChangingEventArgs(propertyName));
}
}
}