forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdentityEqualityComparer.cs
38 lines (36 loc) · 1.31 KB
/
IdentityEqualityComparer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace NHibernate
{
// Since v5.3
[Obsolete("This class has no more usages and will be removed in a future version")]
[Serializable]
public class IdentityEqualityComparer : IEqualityComparer, IEqualityComparer<object>
{
public int GetHashCode(object obj)
{
return RuntimeHelpers.GetHashCode(obj);
}
/// <summary>
/// Performs a null safe comparison using "==" instead of Object.Equals()
/// </summary>
/// <param name="x">First object to compare.</param>
/// <param name="y">Second object to compare.</param>
/// <returns>
/// true if x is the same instance as y or if both are null references; otherwise, false.
///</returns>
/// <remarks>
/// This is Lazy collection safe since it uses <see cref="Object.ReferenceEquals"/>,
/// unlike <c>Object.Equals()</c> which currently causes NHibernate to load up the collection.
/// This behaivior of Collections is likely to change because Java's collections override Equals() and
/// .net's collections don't. So in .net there is no need to override Equals() and
/// GetHashCode() on the NHibernate Collection implementations.
/// </remarks>
public new bool Equals(object x, object y)
{
return ReferenceEquals(x, y);
}
}
}