< Summary

Information
Class: Ice.Internal.DictionaryExtensions
Assembly: Ice
File(s): /_/csharp/src/Ice/Internal/DictionaryExtensions.cs
Tag: 91_21789722663
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 44
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage
100%
Covered methods: 1
Total methods: 1
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
DictionaryEqual<TKey, TValue>(...)100%1010100%

File(s)

/_/csharp/src/Ice/Internal/DictionaryExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3#nullable enable
 4
 5namespace Ice.Internal;
 6
 7/// <summary>
 8/// Extension methods for dictionaries.
 9/// </summary>
 10public static class DictionaryExtensions
 11{
 12    /// <summary>
 13    /// Checks if two dictionaries are equal. The order of the elements in the dictionaries does not matter.
 14    /// </summary>
 15    /// <typeparam name="TKey">The type of the keys in the dictionaries.</typeparam>
 16    /// <typeparam name="TValue">The type of the values in the dictionaries.</typeparam>
 17    /// <param name="lhs">The first dictionary to compare.</param>
 18    /// <param name="rhs">The second dictionary to compare.</param>
 19    /// <param name="valueComparer">The comparer to use to compare the values in the dictionaries or null to use the
 20    /// value's default equality comparer.</param>
 21    /// <returns><see langword="true"/> if the dictionaries are equal; <see langword="false"/>, otherwise.</returns>
 22    public static bool DictionaryEqual<TKey, TValue>(
 23        this IReadOnlyDictionary<TKey, TValue> lhs,
 24        IReadOnlyDictionary<TKey, TValue> rhs,
 25        IEqualityComparer<TValue>? valueComparer = null)
 26    {
 127        if (rhs.Count != lhs.Count)
 28        {
 129            return false;
 30        }
 31
 132        valueComparer ??= EqualityComparer<TValue>.Default;
 33
 134        foreach ((TKey key, TValue value) in lhs)
 35        {
 136            if (!rhs.TryGetValue(key, out TValue? otherValue) || !valueComparer.Equals(value, otherValue))
 37            {
 138                return false;
 39            }
 40        }
 41
 142        return true;
 143    }
 44}