/
dev-npgsql
/
npgsql
Обзор
Документация
Войти
/
dev-npgsql
/
npgsql
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
v8.0.9
src/Npgsql/Shims/ReferenceEqualityComparer.cs
48 строк
2 KB
Nino Floris
Handler rework (#5123)
26 сен 2023, 00:08
Не верифицирован
26 сен 2023, 00:08
0b7aecb
Код
Авторство
О чём код?
using System.Runtime.CompilerServices; namespace System.Collections.Generic; #if NETSTANDARD sealed class ReferenceEqualityComparer : IEqualityComparer<object?>, IEqualityComparer { ReferenceEqualityComparer() { } /// <summary> /// Gets the singleton <see cref="ReferenceEqualityComparer"/> instance. /// </summary> public static ReferenceEqualityComparer Instance { get; } = new(); /// <summary> /// Determines whether two object references refer to the same object instance. /// </summary> /// <param name="x">The first object to compare.</param> /// <param name="y">The second object to compare.</param> /// <returns> /// <see langword="true"/> if both <paramref name="x"/> and <paramref name="y"/> refer to the same object instance /// or if both are <see langword="null"/>; otherwise, <see langword="false"/>. /// </returns> /// <remarks> /// This API is a wrapper around <see cref="object.ReferenceEquals(object?, object?)"/>. /// It is not necessarily equivalent to calling <see cref="object.Equals(object?, object?)"/>. /// </remarks> public new bool Equals(object? x, object? y) => ReferenceEquals(x, y); /// <summary> /// Returns a hash code for the specified object. The returned hash code is based on the object /// identity, not on the contents of the object. /// </summary> /// <param name="obj">The object for which to retrieve the hash code.</param> /// <returns>A hash code for the identity of <paramref name="obj"/>.</returns> /// <remarks> /// This API is a wrapper around <see cref="RuntimeHelpers.GetHashCode(object)"/>. /// It is not necessarily equivalent to calling <see cref="object.GetHashCode()"/>. /// </remarks> public int GetHashCode(object? obj) { // Depending on target framework, RuntimeHelpers.GetHashCode might not be annotated // with the proper nullability attribute. We'll suppress any warning that might // result. return RuntimeHelpers.GetHashCode(obj!); } } #endif