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