< Summary

Information
Class: MyNet.Primitives.Comparers.ReferenceEqualityComparer
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Comparers/ReferenceEqualityComparer.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 63
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Comparers/ReferenceEqualityComparer.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ReferenceEqualityComparer.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System.Collections;
 8using System.Collections.Generic;
 9using System.Runtime.CompilerServices;
 10
 11namespace MyNet.Primitives.Comparers;
 12
 13/// <summary>
 14/// Provides a default instance of a reference equality comparer for objects.
 15/// </summary>
 16public static class ReferenceEqualityComparer
 17{
 18    /// <summary>
 19    /// Gets a singleton instance of <see cref="ReferenceEqualityComparer"/>.
 20    /// </summary>
 321    public static ReferenceEqualityComparer<object> Instance { get; } = new();
 22}
 23
 24/// <summary>
 25/// An equality comparer that compares objects by reference rather than by value.
 26/// </summary>
 27/// <typeparam name="T">The type of objects to compare.</typeparam>
 28public class ReferenceEqualityComparer<T> : IEqualityComparer, IEqualityComparer<T>
 29{
 30    /// <summary>
 31    /// Initializes a new instance of the <see cref="ReferenceEqualityComparer{T}"/> class.
 32    /// </summary>
 33    internal ReferenceEqualityComparer() { }
 34
 35    /// <summary>
 36    /// Returns a hash code for the specified object based on its reference.
 37    /// </summary>
 38    public int GetHashCode(object obj) => RuntimeHelpers.GetHashCode(obj);
 39
 40    /// <summary>
 41    /// Determines whether the specified objects are the same instance (reference equality).
 42    /// </summary>
 43    /// <param name="x">The first object to compare.</param>
 44    /// <param name="y">The second object to compare.</param>
 45    /// <returns><c>true</c> if the specified objects are the same instance; otherwise, <c>false</c>.</returns>
 46    bool IEqualityComparer.Equals(object? x, object? y) => ReferenceEquals(x, y);
 47
 48    /// <summary>
 49    /// Determines whether the specified objects of type <typeparamref name="T"/> are the same instance (reference equal
 50    /// </summary>
 51    /// <param name="x">The first object to compare.</param>
 52    /// <param name="y">The second object to compare.</param>
 53    /// <returns><c>true</c> if the specified objects are the same instance; otherwise, <c>false</c>.</returns>
 54    bool IEqualityComparer<T>.Equals(T? x, T? y) => ReferenceEquals(x, y);
 55
 56    /// <summary>
 57    /// Returns a hash code for the specified object of type <typeparamref name="T"/> based on its reference.
 58    /// </summary>
 59    /// <param name="obj">The object for which to get the hash code.</param>
 60    /// <returns>A hash code for the specified object.</returns>
 61    int IEqualityComparer<T>.GetHashCode(T? obj) => RuntimeHelpers.GetHashCode(obj);
 62}
 63

Methods/Properties

.cctor()