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