@@ -21,14 +21,15 @@ public class DataMetadataComparisonHelper<T> where T : IDataContractComparer
2121 /// </summary>
2222 /// <param name="sourceList">The source set of data contracts.</param>
2323 /// <param name="destinationList">The destination set of data contracts.</param>
24- /// <param name="keyComparer">An instance of <see cref="KeyEqualityComparer {T}"/> used for key comparison.</param>
24+ /// <param name="keyComparer">An instance of <see cref="PropertyEqualityComparer {T}"/> used for key comparison.</param>
2525 /// <returns>A <see cref="Result{T}"/> object containing added, deleted, and edited data contracts, as well as data counts.</returns>
26- public static Result < T > GetDifferences ( HashSet < T > sourceList , HashSet < T > destinationList , KeyEqualityComparer < T > keyComparer , PropertyInfo [ ] CompariableProperties )
26+ public static Result < T > GetDifferences ( HashSet < T > sourceList , HashSet < T > destinationList , PropertyEqualityComparer < T > keyComparer , PropertyInfo [ ] CompariableProperties )
2727 {
2828
2929 List < T > added = new List < T > ( ) ;
3030 List < T > deleted = new List < T > ( ) ;
3131 ConcurrentBag < ( T edit , Dictionary < string , object > updatedProperties ) > edited = new ConcurrentBag < ( T , Dictionary < string , object > ) > ( ) ;
32+ PropertyEqualityComparer < T > CompariablePropertyComparer = new PropertyEqualityComparer < T > ( CompariableProperties ) ;
3233
3334 // Identify added entries
3435 added . AddRange ( sourceList . Except ( destinationList , keyComparer ) ) ;
@@ -39,20 +40,20 @@ public static Result<T> GetDifferences(HashSet<T> sourceList, HashSet<T> destina
3940 // Identify edited entries
4041 var sourceKeyDictionary = sourceList
4142 . Except ( added )
42- . ToDictionary ( row => GenerateCompositeKey ( row , keyComparer . keyProperties ) , row => row ) ;
43+ . ToDictionary ( row => GenerateCompositeKey ( row , keyComparer . properties ) , row => row ) ;
4344
4445 var destinationKeyDictionary = destinationList
4546 . Except ( deleted )
46- . ToDictionary ( row => GenerateCompositeKey ( row , keyComparer . keyProperties ) , row => row ) ;
47+ . ToDictionary ( row => GenerateCompositeKey ( row , keyComparer . properties ) , row => row ) ;
4748
4849 Parallel . ForEach ( sourceKeyDictionary , kvp =>
4950 {
5051 var sourceContract = kvp . Value ;
5152
5253 T ? destinationContract ;
53- if ( destinationKeyDictionary . TryGetValue ( GenerateCompositeKey ( sourceContract , keyComparer . keyProperties ) , out destinationContract ) )
54+ if ( destinationKeyDictionary . TryGetValue ( GenerateCompositeKey ( sourceContract , keyComparer . properties ) , out destinationContract ) )
5455 {
55- var ( isEdited , updatedProperties ) = GetEdited ( sourceContract , destinationContract , CompariableProperties ) ;
56+ var ( isEdited , updatedProperties ) = GetEdited ( sourceContract , destinationContract , CompariablePropertyComparer ) ;
5657
5758 if ( isEdited )
5859 {
@@ -77,40 +78,36 @@ public static Result<T> GetDifferences(HashSet<T> sourceList, HashSet<T> destina
7778 #region Private Methods
7879
7980 /// <summary>
80- /// Compares two entities of type <typeparamref name="T"/> to identify if any properties
81- /// have been edited during synchronization.
81+ /// Compares two instances of the data contract and identifies the properties that have been edited.
8282 /// </summary>
83- /// <param name="source">The original entity before synchronization .</param>
84- /// <param name="destination">The entity in the destination after synchronization .</param>
85- /// <param name="compariableProperties ">The properties to be compared for edits .</param>
83+ /// <param name="source">The source instance to compare .</param>
84+ /// <param name="destination">The destination instance to compare against .</param>
85+ /// <param name="comparablePropertyComparer ">The comparer used to determine which properties are comparable .</param>
8686 /// <returns>
87- /// A tuple where:
88- /// - <see cref="ValueTuple{T1,T2}.Item1"/> is a boolean indicating if any properties were edited.
89- /// - <see cref="ValueTuple{T1,T2}.Item2"/> is a dictionary of updated properties for the edited entity.
87+ /// A tuple indicating whether the instances are edited and a dictionary containing the names and values of the updated properties.
88+ /// If the instances are not edited, returns (false, null).
9089 /// </returns>
91- private static ( bool isEdited , Dictionary < string , object > ? updatedProperties ) GetEdited ( T source , T destination , PropertyInfo [ ] compariableProperties )
90+ private static ( bool isEdited , Dictionary < string , object > ? updatedProperties ) GetEdited ( T source , T destination , PropertyEqualityComparer < T > comparablePropertyComparer )
9291 {
93- if ( source . Equals ( destination ) )
92+ if ( comparablePropertyComparer . Equals ( source , destination ) )
9493 {
9594 return ( false , null ) ;
9695 }
9796
9897 Dictionary < string , object > updatedProperties = new ( ) ;
99- bool isEdited = false ;
100- foreach ( PropertyInfo prop in compariableProperties )
98+ foreach ( PropertyInfo prop in comparablePropertyComparer . properties )
10199 {
102100 object sourceValue = prop . GetValue ( source ) ! ;
103101 object destinationValue = prop . GetValue ( destination ) ! ;
104102
105103 // Compare values
106- if ( ! EqualityComparer < object > . Default . Equals ( sourceValue , destinationValue ) )
104+ if ( ! System . Collections . Generic . EqualityComparer < object > . Default . Equals ( sourceValue , destinationValue ) )
107105 {
108- isEdited = true ;
109106 updatedProperties [ prop . Name ] = sourceValue ;
110107 }
111108 }
112109
113- return ( isEdited , updatedProperties ) ;
110+ return ( true , updatedProperties ) ;
114111 }
115112
116113 /// <summary>
0 commit comments