1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using System . ComponentModel ;
3
4
using System . Runtime . CompilerServices ;
4
5
using System . Threading ;
@@ -17,24 +18,14 @@ class ChatDownloadTask : ITwitchTask
17
18
public int Progress
18
19
{
19
20
get => _progress ;
20
- set
21
- {
22
- if ( value == _progress ) return ;
23
- _progress = value ;
24
- OnPropertyChanged ( ) ;
25
- }
21
+ private set => SetField ( ref _progress , value ) ;
26
22
}
27
23
28
24
private TwitchTaskStatus _status = TwitchTaskStatus . Ready ;
29
25
public TwitchTaskStatus Status
30
26
{
31
27
get => _status ;
32
- private set
33
- {
34
- if ( value == _status ) return ;
35
- _status = value ;
36
- OnPropertyChanged ( ) ;
37
- }
28
+ private set => SetField ( ref _status , value ) ;
38
29
}
39
30
40
31
public ChatDownloadOptions DownloadOptions { get ; init ; }
@@ -46,12 +37,7 @@ private set
46
37
public TwitchTaskException Exception
47
38
{
48
39
get => _exception ;
49
- private set
50
- {
51
- if ( Equals ( value , _exception ) ) return ;
52
- _exception = value ;
53
- OnPropertyChanged ( ) ;
54
- }
40
+ private set => SetField ( ref _exception , value ) ;
55
41
}
56
42
57
43
public string OutputFile => DownloadOptions . Filename ;
@@ -60,12 +46,7 @@ private set
60
46
public bool CanCancel
61
47
{
62
48
get => _canCancel ;
63
- private set
64
- {
65
- if ( value == _canCancel ) return ;
66
- _canCancel = value ;
67
- OnPropertyChanged ( ) ;
68
- }
49
+ private set => SetField ( ref _canCancel , value ) ;
69
50
}
70
51
71
52
public event PropertyChangedEventHandler PropertyChanged ;
@@ -147,5 +128,13 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)
147
128
{
148
129
PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
149
130
}
131
+
132
+ private bool SetField < T > ( ref T field , T value , [ CallerMemberName ] string propertyName = null )
133
+ {
134
+ if ( EqualityComparer < T > . Default . Equals ( field , value ) ) return false ;
135
+ field = value ;
136
+ OnPropertyChanged ( propertyName ) ;
137
+ return true ;
138
+ }
150
139
}
151
140
}
0 commit comments