< Summary

Information
Class: Ice.ProxyIdentityFacetKey
Assembly: Ice
File(s): /_/csharp/src/Ice/ProxyIdentityKey.cs
Tag: 125_37167941578
Line coverage
15%
Covered lines: 2
Uncovered lines: 11
Coverable lines: 13
Total lines: 122
Line coverage: 15.3%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage
33%
Covered methods: 1
Fully covered methods: 1
Total methods: 3
Method coverage: 33.3%
Full method coverage: 33.3%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetHashCode(...)100%11100%
Equals(...)100%210%
Compare(...)0%7280%

File(s)

/_/csharp/src/Ice/ProxyIdentityKey.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3#nullable enable
 4
 5namespace Ice;
 6
 7/// <summary>
 8/// This class allows a proxy to be used as the key for a hashed collection.
 9/// The <c>GetHashCode</c>, <c>Equals</c>, and <c>Compare</c> methods are based on the object identity of the proxy.
 10/// </summary>
 11public class ProxyIdentityKey : System.Collections.IEqualityComparer, System.Collections.IComparer
 12{
 13    /// <summary>
 14    /// Computes a hash value based on the object identity of the provided proxy.
 15    /// </summary>
 16    /// <param name="obj">The proxy whose hash value to compute.</param>
 17    /// <returns>The hash value.</returns>
 18    public int GetHashCode(object obj) => ((ObjectPrx)obj).ice_getIdentity().GetHashCode();
 19
 20    /// <summary>
 21    /// Compares two proxies for equality.
 22    /// </summary>
 23    /// <param name="x">The first proxy to compare.</param>
 24    /// <param name="y">The second proxy to compare.</param>
 25    /// <returns><see langword="true"/> if the passed proxies have the same object identity; otherwise,
 26    /// <see langword="false"/>.</returns>
 27    public new bool Equals(object? x, object? y)
 28    {
 29        try
 30        {
 31            return Compare(x, y) == 0;
 32        }
 33        catch (System.Exception)
 34        {
 35            return false;
 36        }
 37    }
 38
 39    /// <summary>
 40    /// Compares two proxies based on their object identities.
 41    /// </summary>
 42    /// <param name="x">The first proxy to compare.</param>
 43    /// <param name="y">The second proxy to compare.</param>
 44    /// <returns>Less than zero if x is less than y; greater than zero if x is greater than y; otherwise,
 45    /// zero.</returns>
 46    public int Compare(object? x, object? y)
 47    {
 48        var proxy1 = x as ObjectPrx;
 49        if (x is not null && proxy1 is null)
 50        {
 51            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(x));
 52        }
 53
 54        var proxy2 = y as ObjectPrx;
 55        if (y is not null && proxy2 is null)
 56        {
 57            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(y));
 58        }
 59        return Util.proxyIdentityCompare(proxy1, proxy2);
 60    }
 61}
 62
 63/// <summary>
 64/// This class allows a proxy to be used as the key for a hashed collection.
 65/// The <c>GetHashCode</c>, <c>Equals</c>, and <c>Compare</c> methods are based on the object identity and
 66/// the facet of the proxy.
 67/// </summary>
 68public class ProxyIdentityFacetKey : System.Collections.IEqualityComparer, System.Collections.IComparer
 69{
 70    /// <summary>
 71    /// Computes a hash value based on the object identity and facet of the provided proxy.
 72    /// </summary>
 73    /// <param name="obj">The proxy whose hash value to compute.</param>
 74    /// <returns>The hash value.</returns>
 75    public int GetHashCode(object obj)
 76    {
 177        var o = (ObjectPrx)obj;
 178        return HashCode.Combine(o.ice_getIdentity(), o.ice_getFacet());
 79    }
 80
 81    /// <summary>
 82    /// Compares two proxies for equality.
 83    /// </summary>
 84    /// <param name="x">The first proxy to compare.</param>
 85    /// <param name="y">The second proxy to compare.</param>
 86    /// <returns><see langword="true"/> if the passed proxies have the same object identity and facet; otherwise,
 87    /// <see langword="false"/>.</returns>
 88    public new bool Equals(object? x, object? y)
 89    {
 90        try
 91        {
 092            return Compare(x, y) == 0;
 93        }
 094        catch (System.Exception)
 95        {
 096            return false;
 97        }
 098    }
 99
 100    /// <summary>
 101    /// Compares two proxies based on their object identities and facets.
 102    /// </summary>
 103    /// <param name="x">The first proxy to compare.</param>
 104    /// <param name="y">The second proxy to compare.</param>
 105    /// <returns>Less than zero if x is less than y; greater than zero if x is greater than y; otherwise,
 106    /// zero.</returns>
 107    public int Compare(object? x, object? y)
 108    {
 0109        var proxy1 = x as ObjectPrx;
 0110        if (x is not null && proxy1 is null)
 111        {
 0112            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(x));
 113        }
 114
 0115        var proxy2 = y as ObjectPrx;
 0116        if (y is not null && proxy2 is null)
 117        {
 0118            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(y));
 119        }
 0120        return Util.proxyIdentityAndFacetCompare(proxy1, proxy2);
 121    }
 122}