2024-05-12 10:58:04 +03:00

71 lines
2.1 KiB
C#

using ProjectElectricLocomotive.Entities;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.Drawnings;
/// <summary>
/// Реализация сравнения двух объектов класса-прорисовки
/// </summary>
public class DrawiningLocomotiveEqutables : IEqualityComparer<DrawningLocomotive?>
{
public bool Equals(DrawningLocomotive? x, DrawningLocomotive? y)
{
if (x == null || x.EntityLocomotive == null)
{
return false;
}
if (y == null || y.EntityLocomotive == null)
{
return false;
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityLocomotive.Speed != y.EntityLocomotive.Speed)
{
return false;
}
if (x.EntityLocomotive.Weight != y.EntityLocomotive.Weight)
{
return false;
}
if (x.EntityLocomotive.BodyColor != y.EntityLocomotive.BodyColor)
{
return false;
}
if (x is DrawningElectricLocomotive && y is DrawningElectricLocomotive)
{
if(((EntityElectricLocomotive) x.EntityLocomotive).AdditionalColor != ((EntityElectricLocomotive)y.EntityLocomotive).AdditionalColor)
{
return false;
}
if (((EntityElectricLocomotive)x.EntityLocomotive).Pantograph != ((EntityElectricLocomotive)y.EntityLocomotive).Pantograph)
{
return false;
}
if (((EntityElectricLocomotive)x.EntityLocomotive).BatteryStorage != ((EntityElectricLocomotive)y.EntityLocomotive).BatteryStorage)
{
return false;
}
// TODO доделать логику сравнения дополнительных параметров
}
return true;
}
public int GetHashCode([DisallowNull] DrawningLocomotive obj)
{
return obj.GetHashCode();
}
}