src/NetStandard/Collections/Synchronization/src/Utils/IEnumerableICollectionModificationUtils.cs
/// <summary>
/// This method traces moving indexes and determines replace modifications and yield returns this modification with its respective intial old index.
/// </summary>
/// <typeparam name="TOldItem"></typeparam>
/// <typeparam name="TNewItem"></typeparam>
/// <param name="modifications"></param>
/// <returns></returns>
This method traces moving indexes and determines replace modifications and yield returns this modification with its respective intial old index.
This method traces moving indexes and determines replace modifications and yield returns this modification with its respective intial old index .
internal static IEnumerable<(ICollectionModification<TNewItem, TOldItem> Modification, int InitialOldIndex)> YieldTuplesButOnlyReplaceModificationWithInitialOldIndex<TNewItem, TOldItem>(
            IEnumerable<ICollectionModification<TNewItem, TOldItem>> modifications) {
            yield return default;
            var tempModification = new Dictionary<int, (ICollectionModification<TNewItem, TOldItem> Modification, int InitialOldIndex)>();
            foreach (var modification in modifications) {
                if (modification.Action == NotifyCollectionChangedAction.Move) {
                    Debug.Assert(tempModification.Count == 0, "Two move modifications in a row were not expected.");
                    tempModification.Add(modification.NewIndex, (Modification: modification, InitialOldIndex: modification.OldIndex));
                } else if (modification.Action == NotifyCollectionChangedAction.Replace) {
                    if (tempModification.TryGetValue(modification.OldIndex, out var gotValue)) {
                        yield return (Modification: modification, gotValue.InitialOldIndex);
                        tempModification.Remove(modification.OldIndex);
                    } else { 
                        yield return (Modification: modification, modification.OldIndex);
                    }
                }
            }
        }
internal static IEnumerable < ( ICollectionModification < TNewItem , TOldItem > Modification , int InitialOldIndex ) > YieldTuplesButOnlyReplaceModificationWithInitialOldIndex < TNewItem , TOldItem > ( IEnumerable < ICollectionModification < TNewItem , TOldItem > > modifications ) { yield return default ; var tempModification = new Dictionary < int , ( ICollectionModification < TNewItem , TOldItem > Modification , int InitialOldIndex ) > ( ) ; foreach ( var modification in modifications ) { if ( modification . Action == NotifyCollectionChangedAction . Move ) { Debug . Assert ( tempModification . Count == 0 , " " ) ; tempModification . Add ( modification . NewIndex , ( Modification : modification , InitialOldIndex : modification . OldIndex ) ) ; } else if ( modification . Action == NotifyCollectionChangedAction . Replace ) { if ( tempModification . TryGetValue ( modification . OldIndex , out var gotValue ) ) { yield return ( Modification : modification , gotValue . InitialOldIndex ) ; tempModification . Remove ( modification . OldIndex ) ; } else { yield return ( Modification : modification , modification . OldIndex ) ; } } } }
This method traces moving indexes and determines replace modifications and yield returns this modification with its respective intial old index.
This method traces moving indexes and determines replace modifications and yield returns this modification with its respective intial old index .
None
modifications
IEnumerable<ICollectionModification<TNewItem, TOldItem>>
None
typeparam
None
typeparam
None