forked from ddrilling/AsbCloudServer
54 lines
1.2 KiB
C#
54 lines
1.2 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)
|
|
=> (x?.Id??0).CompareTo(y?.Id??0);
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="x"></param>
|
|
/// <param name="y"></param>
|
|
/// <returns></returns>
|
|
public bool Equals(IId? x, IId? y)
|
|
{
|
|
if (x is not null && y is not null)
|
|
return x.Id == y.Id;
|
|
|
|
return x == y;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public int GetHashCode([DisallowNull] IId obj) =>
|
|
obj.GetHashCode();
|
|
|
|
}
|