summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/StateTracking/Comparers/GenericEqualsComparer.cs
blob: cc1d65532d1a1fccaa0aa1e2fe2d775e5a883fbc (plain)
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
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace StardewModdingAPI.Framework.StateTracking.Comparers
{
    /// <summary>Compares values using their <see cref="object.Equals(object)"/> method. This should only be used when <see cref="EquatableComparer{T}"/> won't work, since this doesn't validate whether they're comparable.</summary>
    /// <typeparam name="T">The value type.</typeparam>
    internal class GenericEqualsComparer<T> : IEqualityComparer<T>
    {
        /*********
        ** Public methods
        *********/
        /// <summary>Determines whether the specified objects are equal.</summary>
        /// <returns>true if the specified objects are equal; otherwise, false.</returns>
        /// <param name="x">The first object to compare.</param>
        /// <param name="y">The second object to compare.</param>
        public bool Equals(T x, T y)
        {
            if (x == null)
                return y == null;
            return x.Equals(y);
        }

        /// <summary>Get a hash code for the specified object.</summary>
        /// <param name="obj">The value.</param>
        public int GetHashCode(T obj)
        {
            return RuntimeHelpers.GetHashCode(obj);
        }
    }
}