< Summary

Information
Class: Ice.ProxyIdentityFacetKey
Assembly: Ice
File(s): /home/runner/work/ice/ice/csharp/src/Ice/ProxyIdentityKey.cs
Tag: 71_18251537082
Line coverage
15%
Covered lines: 2
Uncovered lines: 11
Coverable lines: 13
Total lines: 121
Line coverage: 15.3%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage
33%
Covered methods: 1
Total methods: 3
Method coverage: 33.3%

Metrics

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

File(s)

/home/runner/work/ice/ice/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 GetHashCode, Equals, and Compare methods are based on the object identity
 10/// of the proxy.
 11/// </summary>
 12public class ProxyIdentityKey : System.Collections.IEqualityComparer, System.Collections.IComparer
 13{
 14    /// <summary>
 15    /// Computes a hash value based on the object identity of the proxy.
 16    /// </summary>
 17    /// <param name="obj">The proxy whose hash value to compute.</param>
 18    /// <returns>The hash value for the proxy based on the identity.</returns>
 19    public int GetHashCode(object obj) => ((ObjectPrx)obj).ice_getIdentity().GetHashCode();
 20
 21    /// <summary>
 22    /// Compares two proxies for equality.
 23    /// </summary>
 24    /// <param name="x">The first proxy to compare.</param>
 25    /// <param name="y">The second proxy to compare.</param>
 26    /// <returns>True if the passed proxies have the same object identity; false, otherwise.</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 using the object identity for comparison.
 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 zero.</returns>
 45    public int Compare(object? x, object? y)
 46    {
 47        var proxy1 = x as ObjectPrx;
 48        if (x is not null && proxy1 is null)
 49        {
 50            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(x));
 51        }
 52
 53        var proxy2 = y as ObjectPrx;
 54        if (y is not null && proxy2 is null)
 55        {
 56            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(y));
 57        }
 58        return Util.proxyIdentityCompare(proxy1, proxy2);
 59    }
 60}
 61
 62/// <summary>
 63/// This class allows a proxy to be used as the key for a hashed collection.
 64/// The GetHashCode, Equals, and Compare methods are based on the object identity and
 65/// the facet of the proxy.
 66/// </summary>
 67public class ProxyIdentityFacetKey : System.Collections.IEqualityComparer, System.Collections.IComparer
 68{
 69    /// <summary>
 70    /// Computes a hash value based on the object identity and facet of the proxy.
 71    /// </summary>
 72    /// <param name="obj">The proxy whose hash value to compute.</param>
 73    /// <returns>The hash value for the proxy based on the identity and facet.</returns>
 74    public int GetHashCode(object obj)
 75    {
 176        var o = (ObjectPrx)obj;
 177        return HashCode.Combine(o.ice_getIdentity(), o.ice_getFacet());
 78    }
 79
 80    /// <summary>
 81    /// Compares two proxies for equality.
 82    /// </summary>
 83    /// <param name="x">The first proxy to compare.</param>
 84    /// <param name="y">The second proxy to compare.</param>
 85    /// <returns>True if the passed proxies have the same object
 86    /// identity and facet; false, otherwise.</returns>
 87    public new bool Equals(object? x, object? y)
 88    {
 89        try
 90        {
 091            return Compare(x, y) == 0;
 92        }
 093        catch (System.Exception)
 94        {
 095            return false;
 96        }
 097    }
 98
 99    /// <summary>
 100    /// Compares two proxies using the object identity and facet for comparison.
 101    /// </summary>
 102    /// <param name="x">The first proxy to compare.</param>
 103    /// <param name="y">The second proxy to compare.</param>
 104    /// <returns>&lt; 0 if x is less than y; &gt; 0 if x is greater than y;
 105    /// 0, otherwise.</returns>
 106    public int Compare(object? x, object? y)
 107    {
 0108        var proxy1 = x as ObjectPrx;
 0109        if (x is not null && proxy1 is null)
 110        {
 0111            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(x));
 112        }
 113
 0114        var proxy2 = y as ObjectPrx;
 0115        if (y is not null && proxy2 is null)
 116        {
 0117            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(y));
 118        }
 0119        return Util.proxyIdentityAndFacetCompare(proxy1, proxy2);
 120    }
 121}