DD.WellWorkover.Cloud/AsbCloudApp/Comparators/ComparerIId.cs
2023-02-22 09:00:47 +05:00

59 lines
1.5 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();
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)
{
if (x is null || y is null)
return 0;
else
return x.Id.CompareTo(y.Id);
}
/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public bool Equals(IId? x, IId? y)
{
if (x is null || y is null)
return false;
else
return x.Id == y.Id;
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public int GetHashCode([DisallowNull] IId obj) =>
obj.GetHashCode();
}
}