@@ -60,8 +60,8 @@ public void AddRange(IEnumerable<T> collection)
60
60
foreach ( var i in changedItems )
61
61
Items . Add ( i ) ;
62
62
63
- OnPropertyChanged ( new PropertyChangedEventArgs ( CountName ) ) ;
64
- OnPropertyChanged ( new PropertyChangedEventArgs ( IndexerName ) ) ;
63
+ OnCountPropertyChanged ( ) ;
64
+ OnIndexerPropertyChanged ( ) ;
65
65
OnCollectionChanged ( new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Add , changedItems , startIndex ) ) ;
66
66
}
67
67
@@ -81,16 +81,13 @@ public void ReplaceRange(IEnumerable<T> collection)
81
81
82
82
CheckReentrancy ( ) ;
83
83
84
- var oldItems = new List < T > ( Items ) ;
85
- var changedItems = new List < T > ( collection ) ;
86
-
87
84
Items . Clear ( ) ;
88
- foreach ( var i in changedItems )
85
+ foreach ( var i in collection )
89
86
Items . Add ( i ) ;
90
87
91
- OnPropertyChanged ( new PropertyChangedEventArgs ( CountName ) ) ;
92
- OnPropertyChanged ( new PropertyChangedEventArgs ( IndexerName ) ) ;
93
- OnCollectionChanged ( new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Replace , changedItems , oldItems ) ) ;
88
+ OnCountPropertyChanged ( ) ;
89
+ OnIndexerPropertyChanged ( ) ;
90
+ OnCollectionReset ( ) ;
94
91
}
95
92
96
93
/// <summary>
@@ -121,8 +118,8 @@ public void RemoveRange(IEnumerable<T> collection)
121
118
122
119
if ( changedItems . Count > 0 )
123
120
{
124
- OnPropertyChanged ( new PropertyChangedEventArgs ( CountName ) ) ;
125
- OnPropertyChanged ( new PropertyChangedEventArgs ( IndexerName ) ) ;
121
+ OnCountPropertyChanged ( ) ;
122
+ OnIndexerPropertyChanged ( ) ;
126
123
OnCollectionChanged ( new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Remove , changedItems ) ) ;
127
124
}
128
125
}
@@ -135,15 +132,34 @@ public void Replace(T item)
135
132
{
136
133
CheckReentrancy ( ) ;
137
134
138
- var oldItems = new List < T > ( Items ) ;
139
- var changedItems = new List < T > { item } ;
140
-
141
135
Items . Clear ( ) ;
142
136
Items . Add ( item ) ;
143
137
144
- OnPropertyChanged ( new PropertyChangedEventArgs ( CountName ) ) ;
145
- OnPropertyChanged ( new PropertyChangedEventArgs ( IndexerName ) ) ;
146
- OnCollectionChanged ( new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Replace , changedItems , oldItems ) ) ;
138
+ OnCountPropertyChanged ( ) ;
139
+ OnIndexerPropertyChanged ( ) ;
140
+ OnCollectionChanged ( new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Reset ) ) ;
141
+ }
142
+
143
+ private void OnCountPropertyChanged ( )
144
+ {
145
+ OnPropertyChanged ( EventArgsCache . CountPropertyChanged ) ;
146
+ }
147
+
148
+ private void OnIndexerPropertyChanged ( )
149
+ {
150
+ OnPropertyChanged ( EventArgsCache . IndexerPropertyChanged ) ;
151
+ }
152
+
153
+ private void OnCollectionReset ( )
154
+ {
155
+ OnCollectionChanged ( EventArgsCache . ResetCollectionChanged ) ;
156
+ }
157
+
158
+ private static class EventArgsCache
159
+ {
160
+ internal static readonly PropertyChangedEventArgs CountPropertyChanged = new PropertyChangedEventArgs ( CountName ) ;
161
+ internal static readonly PropertyChangedEventArgs IndexerPropertyChanged = new PropertyChangedEventArgs ( IndexerName ) ;
162
+ internal static readonly NotifyCollectionChangedEventArgs ResetCollectionChanged = new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Reset ) ;
147
163
}
148
164
}
149
165
}
0 commit comments