< Summary

Information
Class: Ice.ProxyIdentityFacetKey
Assembly: Ice
File(s): /_/csharp/src/Ice/ProxyIdentityKey.cs
Tag: 91_21789722663
Line coverage
15%
Covered lines: 2
Uncovered lines: 11
Coverable lines: 13
Total lines: 120
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)

/_/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; <see langword="false"/>,
 26    /// 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 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 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 <c>GetHashCode</c>, <c>Equals</c>, and <c>Compare</c> 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 provided proxy.
 71    /// </summary>
 72    /// <param name="obj">The proxy whose hash value to compute.</param>
 73    /// <returns>The hash value.</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><see langword="true"/> if the passed proxies have the same object identity and facet;
 86    /// <see langword="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 based on their object identities and facets.
 101    /// </summary>
 102    /// <param name="x">The first proxy to compare.</param>
 103    /// <param name="y">The second proxy to compare.</param>
 104    /// <returns>Less than zero if x is less than y; greater than zero if x is greater than y; otherwise zero.</returns>
 105    public int Compare(object? x, object? y)
 106    {
 0107        var proxy1 = x as ObjectPrx;
 0108        if (x is not null && proxy1 is null)
 109        {
 0110            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(x));
 111        }
 112
 0113        var proxy2 = y as ObjectPrx;
 0114        if (y is not null && proxy2 is null)
 115        {
 0116            throw new ArgumentException("Argument must be derived from Ice.ObjectPrx", nameof(y));
 117        }
 0118        return Util.proxyIdentityAndFacetCompare(proxy1, proxy2);
 119    }
 120}