| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | namespace IceRpc.Internal; |
| | 4 | |
|
| | 5 | | /// <summary>Extension methods for dictionaries.</summary> |
| | 6 | | internal static class DictionaryExtensions |
| | 7 | | { |
| | 8 | | /// <summary>Checks if two dictionaries are equal. The order of the elements in the dictionaries does not |
| | 9 | | /// matter.</summary> |
| | 10 | | internal static bool DictionaryEqual<TKey, TValue>( |
| | 11 | | this IReadOnlyDictionary<TKey, TValue> lhs, |
| | 12 | | IReadOnlyDictionary<TKey, TValue> rhs, |
| | 13 | | IEqualityComparer<TValue>? valueComparer = null) |
| 1691 | 14 | | { |
| 1691 | 15 | | if (rhs.Count != lhs.Count) |
| 2 | 16 | | { |
| 2 | 17 | | return false; |
| | 18 | | } |
| | 19 | |
|
| 1689 | 20 | | valueComparer ??= EqualityComparer<TValue>.Default; |
| | 21 | |
|
| 5291 | 22 | | foreach ((TKey key, TValue value) in lhs) |
| 115 | 23 | | { |
| 115 | 24 | | if (!rhs.TryGetValue(key, out TValue? otherValue) || !valueComparer.Equals(value, otherValue)) |
| 6 | 25 | | { |
| 6 | 26 | | return false; |
| | 27 | | } |
| 109 | 28 | | } |
| | 29 | |
|
| 1683 | 30 | | return true; |
| 1691 | 31 | | } |
| | 32 | | } |