Skip to content

Commit 30c42b3

Browse files
fix: update the hash code for the list so it can be retrieved from dictionary correctly (#2390)
1 parent aef7faa commit 30c42b3

File tree

1 file changed

+26
-1
lines changed
  • src/Confluent.SchemaRegistry/Rest/DataContracts

1 file changed

+26
-1
lines changed

src/Confluent.SchemaRegistry/Rest/DataContracts/Schema.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,37 @@ public override int GetHashCode()
271271
unchecked
272272
{
273273
var hashCode = SchemaString.GetHashCode();
274-
hashCode = (hashCode * 397) ^ (References != null ? References.GetHashCode() : 0);
274+
hashCode = (hashCode * 397) ^ (References != null ? GetListHashCode(References) : 0);
275275
hashCode = (hashCode * 397) ^ (Metadata != null ? Metadata.GetHashCode() : 0);
276276
hashCode = (hashCode * 397) ^ (RuleSet != null ? RuleSet.GetHashCode() : 0);
277277
return hashCode;
278278
}
279279
}
280+
281+
/// <summary>
282+
/// Returns a hash code for a list of objects.
283+
/// </summary>
284+
/// <param name="list">
285+
/// The list to get the hash code for.
286+
/// </param>
287+
/// <returns>
288+
/// An integer that specifies a hash value for this instance.
289+
/// </returns>
290+
private int GetListHashCode<T>(IList<T> list)
291+
{
292+
if (list == null || list.Count == 0)
293+
return 0;
294+
295+
unchecked
296+
{
297+
int hash = 0;
298+
foreach (var item in list)
299+
{
300+
hash += item?.GetHashCode() ?? 0;
301+
}
302+
return hash;
303+
}
304+
}
280305

281306
/// <summary>
282307
/// Compares this instance with another instance of this object type and indicates whether

0 commit comments

Comments
 (0)