@@ -81,6 +81,36 @@ private static string FormatPropertyValue(object? value)
8181 return value . ToString ( ) ;
8282 }
8383
84+ /// <summary>
85+ /// Compares two property values for equality, handling collections and complex objects appropriately.
86+ /// </summary>
87+ /// <param name="oldValue">The old property value.</param>
88+ /// <param name="newValue">The new property value.</param>
89+ /// <returns>True if the values are equal, false otherwise.</returns>
90+ private static bool ArePropertyValuesEqual ( object ? oldValue , object ? newValue )
91+ {
92+ // Handle null cases
93+ if ( oldValue == null && newValue == null ) return true ;
94+ if ( oldValue == null || newValue == null ) return false ;
95+
96+ // Handle collections specially
97+ if ( oldValue is System . Collections . IEnumerable oldEnumerable &&
98+ newValue is System . Collections . IEnumerable newEnumerable &&
99+ ! ( oldValue is string ) && ! ( newValue is string ) )
100+ {
101+ var oldItems = oldEnumerable . Cast < object > ( ) . ToList ( ) ;
102+ var newItems = newEnumerable . Cast < object > ( ) . ToList ( ) ;
103+
104+ if ( oldItems . Count != newItems . Count ) return false ;
105+
106+ // Use SequenceEqual for proper comparison
107+ return oldItems . SequenceEqual ( newItems ) ;
108+ }
109+
110+ // For non-collections, use standard equality
111+ return object . Equals ( oldValue , newValue ) ;
112+ }
113+
84114 /// <summary>
85115 /// Compares two policy objects of the same type using reflection to detect property-level changes.
86116 /// Only properties that are non-null in the new policy and differ from the old policy are considered changes.
@@ -113,7 +143,7 @@ private static string FormatPropertyValue(object? value)
113143 var oldValue = oldPolicy != null ? prop . GetValue ( oldPolicy ) : null ;
114144 var newValue = prop . GetValue ( newPolicy ) ;
115145
116- if ( newValue != null && ! object . Equals ( oldValue , newValue ) )
146+ if ( newValue != null && ! ArePropertyValuesEqual ( oldValue , newValue ) )
117147 {
118148 var oldValueStr = FormatPropertyValue ( oldValue ) ;
119149 var newValueStr = FormatPropertyValue ( newValue ) ;
0 commit comments