public static IEnumerable <IChangeSet <TItem> > CompareTo <TItem>(this HashSet <TItem> @this, HashSet <TItem> other) { if (@this == null) { throw new NullReferenceException(); } if (other == null) { throw new ArgumentNullException(nameof(other)); } #if NET40 Contract.EndContractBlock(); #endif var keys = @this.Concat(other).Distinct(@this.Comparer); foreach (var key in keys) { if (!other.Contains(key)) { yield return(new ChangeSet <TItem>(ChangeType.Added, key)); continue; } if ([email protected](key)) { yield return(new ChangeSet <TItem>(ChangeType.Removed, key)); continue; } yield return(new ChangeSet <TItem>(ChangeType.Equal, key)); } }