< Summary

Information
Class: MyNet.Primitives.Comparers.PredicateEqualityComparer<T>
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Comparers/PredicateEqualityComparer.cs
Tag: 323_28699572109
Line coverage
75%
Covered lines: 3
Uncovered lines: 1
Coverable lines: 4
Total lines: 50
Line coverage: 75%
Branch coverage
75%
Covered branches: 9
Total branches: 12
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="PredicateEqualityComparer.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections;
 9using System.Collections.Generic;
 10using System.Runtime.CompilerServices;
 11
 12namespace MyNet.Primitives.Comparers;
 13
 14/// <summary>
 15/// An equality comparer that uses a predicate function to determine equality.
 16/// </summary>
 17/// <typeparam name="T">Type of objects to compare.</typeparam>
 18public class PredicateEqualityComparer<T>(Func<T, T, bool> predicate) : IEqualityComparer, IEqualityComparer<T>
 19{
 20    /// <summary>
 21    /// Returns a hash code for the specified object.
 22    /// This implementation uses <see cref="RuntimeHelpers.GetHashCode(object)"/> which is based on object identity.
 23    /// </summary>
 324    public int GetHashCode(object obj) => RuntimeHelpers.GetHashCode(obj);
 25
 26    /// <summary>
 27    /// Determines whether the specified objects are equal using the provided predicate function.
 28    /// </summary>
 29    /// <param name="x">The first object to compare.</param>
 30    /// <param name="y">The second object to compare.</param>
 31    /// <returns><c>true</c> if the specified objects are equal; otherwise, <c>false</c>.</returns>
 332    bool IEqualityComparer.Equals(object? x, object? y) => x is not null && y is not null && !ReferenceEquals(x, y) && p
 33
 34    /// <summary>
 35    /// Determines whether the specified objects of type <typeparamref name="T"/> are equal using the provided predicate
 36    /// </summary>
 37    /// <param name="x">The first object to compare.</param>
 38    /// <param name="y">The second object to compare.</param>
 39    /// <returns><c>true</c> if the specified objects are equal; otherwise, <c>false</c>.</returns>
 1540    bool IEqualityComparer<T>.Equals(T? x, T? y) => x is not null && y is not null && !ReferenceEquals(x, y) && predicat
 41
 42    /// <summary>
 43    /// Returns a hash code for the specified object of type <typeparamref name="T"/>.
 44    /// This implementation uses <see cref="RuntimeHelpers.GetHashCode(object)"/> which is based on object identity.
 45    /// </summary>
 46    /// <param name="obj">The object for which to get the hash code.</param>
 47    /// <returns>A hash code for the specified object.</returns>
 048    int IEqualityComparer<T>.GetHashCode(T? obj) => RuntimeHelpers.GetHashCode(obj);
 49}
 50