@@ -24,9 +24,11 @@ public class ItemsProcessing<TSourceItem, TReturnValue> : CollectionComputing<TR
2424
2525 public Func < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , object , EventArgs , TReturnValue > NewItemProcessor => _newItemProcessor ;
2626 public Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > OldItemProcessor => _oldItemProcessor ;
27+ public Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > MoveItemProcessor => _moveItemProcessor ;
2728
2829 private readonly Func < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , object , EventArgs , TReturnValue > _newItemProcessor ;
2930 private readonly Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > _oldItemProcessor ;
31+ private readonly Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > _moveItemProcessor ;
3032
3133 // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
3234 private readonly PropertyChangedEventHandler _sourceScalarPropertyChangedEventHandler ;
@@ -45,7 +47,8 @@ public class ItemsProcessing<TSourceItem, TReturnValue> : CollectionComputing<TR
4547 public ItemsProcessing (
4648 IReadScalar < INotifyCollectionChanged > sourceScalar ,
4749 Func < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , object , EventArgs , TReturnValue > newItemProcessor = null ,
48- Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > oldItemProcessor = null ) : this ( newItemProcessor , oldItemProcessor , Utils . getCapacity ( sourceScalar ) )
50+ Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > oldItemProcessor = null ,
51+ Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > moveItemProcessor = null ) : this ( newItemProcessor , oldItemProcessor , moveItemProcessor , Utils . getCapacity ( sourceScalar ) )
4952 {
5053 _sourceScalar = sourceScalar ;
5154 _sourceScalarPropertyChangedEventHandler = handleSourceScalarValueChanged ;
@@ -59,19 +62,22 @@ public ItemsProcessing(
5962 public ItemsProcessing (
6063 INotifyCollectionChanged source ,
6164 Func < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , object , EventArgs , TReturnValue > newItemProcessor = null ,
62- Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > oldItemProcessor = null ) : this ( newItemProcessor , oldItemProcessor , Utils . getCapacity ( source ) )
65+ Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > oldItemProcessor = null ,
66+ Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > moveItemProcessor = null ) : this ( newItemProcessor , oldItemProcessor , moveItemProcessor , Utils . getCapacity ( source ) )
6367 {
6468 _source = source ;
6569 initializeFromSource ( null , null ) ;
6670 }
6771
6872 private ItemsProcessing (
6973 Func < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , object , EventArgs , TReturnValue > newItemProcessor ,
70- Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > oldItemProcessor ,
74+ Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > oldItemProcessor ,
75+ Action < TSourceItem , ItemsProcessing < TSourceItem , TReturnValue > , TReturnValue , object , EventArgs > moveItemProcessor ,
7176 int capacity ) : base ( capacity )
7277 {
7378 _newItemProcessor = newItemProcessor ;
7479 _oldItemProcessor = oldItemProcessor ;
80+ _moveItemProcessor = moveItemProcessor ;
7581 }
7682
7783 private void initializeFromSource ( object sender , EventArgs eventArgs )
@@ -86,7 +92,7 @@ private void initializeFromSource(object sender, EventArgs eventArgs)
8692 TSourceItem sourceItem = _sourceAsList [ i ] ;
8793 TReturnValue returnValue = this [ 0 ] ;
8894 baseRemoveItem ( 0 ) ;
89- processOldItem ( sourceItem , returnValue , sender , eventArgs ) ;
95+ if ( _oldItemProcessor != null ) processOldItem ( sourceItem , returnValue , sender , eventArgs ) ;
9096 }
9197
9298 if ( _rootSourceWrapper )
@@ -125,7 +131,7 @@ private void initializeFromSource(object sender, EventArgs eventArgs)
125131 for ( int index = 0 ; index < count ; index ++ )
126132 {
127133 TSourceItem sourceItem = _sourceAsList [ index ] ;
128- TReturnValue returnValue = processNewItem ( sourceItem , sender , eventArgs ) ;
134+ TReturnValue returnValue = _newItemProcessor != null ? processNewItem ( sourceItem , sender , eventArgs ) : default ( TReturnValue ) ;
129135
130136 baseInsertItem ( index , returnValue ) ;
131137 }
@@ -172,7 +178,7 @@ private void handleSourceCollectionChanged(object sender, NotifyCollectionChange
172178 _isConsistent = false ;
173179 int newStartingIndex = e . NewStartingIndex ;
174180 TSourceItem addedItem = _sourceAsList [ newStartingIndex ] ;
175- TReturnValue returnValue = processNewItem ( addedItem , sender , e ) ;
181+ TReturnValue returnValue = _newItemProcessor != null ? processNewItem ( addedItem , sender , e ) : default ( TReturnValue ) ;
176182
177183 baseInsertItem ( newStartingIndex , returnValue ) ;
178184 _isConsistent = true ;
@@ -184,7 +190,7 @@ private void handleSourceCollectionChanged(object sender, NotifyCollectionChange
184190 TSourceItem removedItem = ( TSourceItem ) e . OldItems [ 0 ] ;
185191 TReturnValue returnValue1 = this [ oldStartingIndex ] ;
186192 baseRemoveItem ( oldStartingIndex ) ;
187- processOldItem ( removedItem , returnValue1 , sender , e ) ;
193+ if ( _oldItemProcessor != null ) processOldItem ( removedItem , returnValue1 , sender , e ) ;
188194 _isConsistent = true ;
189195 raiseConsistencyRestored ( ) ;
190196 break ;
@@ -195,9 +201,9 @@ private void handleSourceCollectionChanged(object sender, NotifyCollectionChange
195201 TSourceItem newItem = _sourceAsList [ newStartingIndex1 ] ;
196202 TReturnValue returnValueOld = this [ newStartingIndex1 ] ;
197203
198- TReturnValue returnValue2 = processNewItem ( newItem , sender , e ) ;
204+ TReturnValue returnValue2 = _newItemProcessor != null ? processNewItem ( newItem , sender , e ) : default ;
199205 baseSetItem ( newStartingIndex1 , returnValue2 ) ;
200- processOldItem ( oldItem , returnValueOld , sender , e ) ;
206+ if ( _oldItemProcessor != null ) processOldItem ( oldItem , returnValueOld , sender , e ) ;
201207 _isConsistent = true ;
202208 raiseConsistencyRestored ( ) ;
203209 break ;
@@ -207,6 +213,7 @@ private void handleSourceCollectionChanged(object sender, NotifyCollectionChange
207213 if ( oldStartingIndex2 != newStartingIndex2 )
208214 {
209215 baseMoveItem ( oldStartingIndex2 , newStartingIndex2 ) ;
216+ if ( _moveItemProcessor != null ) processMovedItem ( _sourceAsList [ newStartingIndex2 ] , this [ newStartingIndex2 ] , sender , e ) ;
210217 }
211218 break ;
212219 case NotifyCollectionChangedAction . Reset :
@@ -220,46 +227,57 @@ private void handleSourceCollectionChanged(object sender, NotifyCollectionChange
220227
221228 private TReturnValue processNewItem ( TSourceItem sourceItem , object sender , EventArgs eventArgs )
222229 {
223- if ( _newItemProcessor != null )
230+ if ( Configuration . TrackComputingsExecutingUserCode )
224231 {
225- if ( Configuration . TrackComputingsExecutingUserCode )
226- {
227- Thread currentThread = Thread . CurrentThread ;
228- DebugInfo . _computingsExecutingUserCode . TryGetValue ( currentThread , out IComputing computing ) ;
229- DebugInfo . _computingsExecutingUserCode [ currentThread ] = this ;
230-
231- TReturnValue returnValue = _newItemProcessor ( sourceItem , this , sender , eventArgs ) ;
232+ Thread currentThread = Thread . CurrentThread ;
233+ DebugInfo . _computingsExecutingUserCode . TryGetValue ( currentThread , out IComputing computing ) ;
234+ DebugInfo . _computingsExecutingUserCode [ currentThread ] = this ;
235+
236+ TReturnValue returnValue = _newItemProcessor ( sourceItem , this , sender , eventArgs ) ;
237+
238+ if ( computing == null ) DebugInfo . _computingsExecutingUserCode . Remove ( currentThread ) ;
239+ else DebugInfo . _computingsExecutingUserCode [ currentThread ] = computing ;
240+ return returnValue ;
241+ }
232242
233- if ( computing == null ) DebugInfo . _computingsExecutingUserCode . Remove ( currentThread ) ;
234- else DebugInfo . _computingsExecutingUserCode [ currentThread ] = computing ;
235- return returnValue ;
236- }
243+ return _newItemProcessor ( sourceItem , this , sender , eventArgs ) ;
244+ }
245+
246+ private void processOldItem ( TSourceItem sourceItem , TReturnValue returnValue , object sender , EventArgs eventArgs )
247+ {
248+ if ( Configuration . TrackComputingsExecutingUserCode )
249+ {
250+ Thread currentThread = Thread . CurrentThread ;
251+ DebugInfo . _computingsExecutingUserCode . TryGetValue ( currentThread , out IComputing computing ) ;
252+ DebugInfo . _computingsExecutingUserCode [ currentThread ] = this ;
253+
254+ _oldItemProcessor ( sourceItem , this , returnValue , sender , eventArgs ) ;
237255
238- return _newItemProcessor ( sourceItem , this , sender , eventArgs ) ;
256+ if ( computing == null ) DebugInfo . _computingsExecutingUserCode . Remove ( currentThread ) ;
257+ else DebugInfo . _computingsExecutingUserCode [ currentThread ] = computing ;
258+ return ;
239259 }
240260
241- return default ;
261+ _oldItemProcessor ( sourceItem , this , returnValue , sender , eventArgs ) ;
242262 }
243263
244- private void processOldItem ( TSourceItem sourceItem , TReturnValue returnValue , object sender , EventArgs eventArgs )
264+
265+ private void processMovedItem ( TSourceItem sourceItem , TReturnValue returnValue , object sender , EventArgs eventArgs )
245266 {
246- if ( _oldItemProcessor != null )
267+ if ( Configuration . TrackComputingsExecutingUserCode )
247268 {
248- if ( Configuration . TrackComputingsExecutingUserCode )
249- {
250- Thread currentThread = Thread . CurrentThread ;
251- DebugInfo . _computingsExecutingUserCode . TryGetValue ( currentThread , out IComputing computing ) ;
252- DebugInfo . _computingsExecutingUserCode [ currentThread ] = this ;
253-
254- _oldItemProcessor ( sourceItem , this , returnValue , sender , eventArgs ) ;
255-
256- if ( computing == null ) DebugInfo . _computingsExecutingUserCode . Remove ( currentThread ) ;
257- else DebugInfo . _computingsExecutingUserCode [ currentThread ] = computing ;
258- return ;
259- }
269+ Thread currentThread = Thread . CurrentThread ;
270+ DebugInfo . _computingsExecutingUserCode . TryGetValue ( currentThread , out IComputing computing ) ;
271+ DebugInfo . _computingsExecutingUserCode [ currentThread ] = this ;
272+
273+ _moveItemProcessor ( sourceItem , this , returnValue , sender , eventArgs ) ;
260274
261- _oldItemProcessor ( sourceItem , this , returnValue , sender , eventArgs ) ;
275+ if ( computing == null ) DebugInfo . _computingsExecutingUserCode . Remove ( currentThread ) ;
276+ else DebugInfo . _computingsExecutingUserCode [ currentThread ] = computing ;
277+ return ;
262278 }
279+
280+ _moveItemProcessor ( sourceItem , this , returnValue , sender , eventArgs ) ;
263281 }
264282
265283 ~ ItemsProcessing ( )
0 commit comments