You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[TestMethod]publicvoidCompare_Id_Identity(){varsource=new[]{(1,"A"),(2,"B"),(3,"C")};varmodified=new[]{(2,"B"),(3,"D"),(4,"E")};var(inserted,updated,deleted)=source.Compare(modified, x =>x.Item1);CollectionAssert.AreEqual(new[]{(4,"E")},inserted.ToArray());CollectionAssert.AreEqual(new[]{(3,"D")},updated.ToArray());CollectionAssert.AreEqual(new[]{(1,"A")},deleted.ToArray());}
Library code is:
publicstaticclassSequenceChange{publicstatic(IEnumerable<T>Inserted,IEnumerable<T>Deleted)Compare<T>(thisIEnumerable<T>source,IEnumerable<T>modified)=>source.Compare(modified,EqualityComparer<T>.Default);publicstatic(IEnumerable<T>Inserted,IEnumerable<T>Deleted)Compare<T>(thisIEnumerable<T>source,IEnumerable<T>modified,IEqualityComparer<T>comparer)=>(modified.Except(source,comparer),source.Except(modified,comparer));publicstatic(IEnumerable<T>Inserted,IEnumerable<T>Updated,IEnumerable<T>Deleted)Compare<T,TKey>(thisIEnumerable<T>source,IEnumerable<T>modified,Func<T,TKey>keySelector)=>source.Compare(modified,keySelector,EqualityComparer<T>.Default);publicstatic(IEnumerable<T>Inserted,IEnumerable<T>Updated,IEnumerable<T>Deleted)Compare<T,TKey>(thisIEnumerable<T>source,IEnumerable<T>modified,Func<T,TKey>keySelector,IEqualityComparer<T>comparer)=>(modified.ExceptBy(source,keySelector),fromsinsource
join minmodified on keySelector(s) equals keySelector(m)where!comparer.Equals(s,m)selectm,source.ExceptBy(modified,keySelector));}
The text was updated successfully, but these errors were encountered:
@dmitrynogin Thanks for your proposal but I think ListDiff by @praeclarum should be quite sufficient for this so I don't see much point/motivation in maintaining duplicate functionality separately as part of this library.
What about adding extensions allowing producing "diffgrams" between sequences of objects with value and id identity?
The desired behavior would be:
And:
Library code is:
The text was updated successfully, but these errors were encountered: