PIbd-13_Ladyagin_P.D._Simple/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawningAirplaneEqutables.cs
2024-06-09 18:11:19 +04:00

69 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectAirplaneWithRadar.Entities;
namespace ProjectAirplaneWithRadar.Drawnings
{
/// <summary>
/// Реализация сравнения двух объектов класса-прорисовки
/// </summary>
public class DrawningAirplaneEqutables : IEqualityComparer<DrawningAirplane?>
{
public bool Equals(DrawningAirplane? x, DrawningAirplane? y)
{
if (x == null || x.EntityAirplane == null)
{
return false;
}
if (y == null || y.EntityAirplane == null)
{
return false;
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityAirplane.Speed != y.EntityAirplane.Speed)
{
return false;
}
if (x.EntityAirplane.Weight != y.EntityAirplane.Weight)
{
return false;
}
if (x.EntityAirplane.BodyColor != y.EntityAirplane.BodyColor)
{
return false;
}
if (x is DrawingAirplaneWithRadar && y is DrawingAirplaneWithRadar)
{
EntityAirplaneWithRadar entityX = (EntityAirplaneWithRadar)x.EntityAirplane;
EntityAirplaneWithRadar entityY = (EntityAirplaneWithRadar)y.EntityAirplane;
if (entityX.AdditionalColor != entityY.AdditionalColor)
{
return false;
}
if (entityX.Wheels != entityY.Wheels)
{
return false;
}
if (entityX.Radar != entityY.Radar)
{
return false;
}
}
return true;
}
public int GetHashCode([DisallowNull] DrawningAirplane obj)
{
return obj.GetHashCode();
}
}
}