DD.WellWorkover.Cloud/AsbCloudApp/Comparators/ComparerIId.cs
2022-05-06 13:50:26 +05:00

49 lines
1.3 KiB
C#

using AsbCloudApp.Data;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace AsbCloudApp.Comparators
{
/// <summary>
/// Компаратор для сравнения сущностей по ID
/// </summary>
public class ComparerIId : IComparer<IId>, IEqualityComparer<IId>
{
private static readonly ComparerIId instance = new ComparerIId();
private ComparerIId() { }
/// <summary>
/// Singleton ссылка
/// </summary>
/// <returns></returns>
public static ComparerIId GetInstance() => instance;
/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public int Compare(IId x, IId y) =>
x.Id.CompareTo(y.Id);
/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public bool Equals(IId x, IId y) =>
x.Id == y.Id;
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public int GetHashCode([DisallowNull] IId obj) =>
obj.GetHashCode();
}
}