66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using ProjectMonorail.Entities;
|
||
using System.Diagnostics.CodeAnalysis;
|
||
|
||
namespace ProjectMonorail.Drawings;
|
||
|
||
/// <summary>
|
||
/// Реализация сравнения двух объектов класса-прорисовки
|
||
/// </summary>
|
||
public class DrawingTrainEqutables : IEqualityComparer<DrawingTrain?>
|
||
{
|
||
public bool Equals(DrawingTrain? x, DrawingTrain? y)
|
||
{
|
||
if (x == null || x.EntityTrain == null)
|
||
{
|
||
return false;
|
||
}
|
||
if (y == null || y.EntityTrain == null)
|
||
{
|
||
return false;
|
||
}
|
||
if (x.GetType().Name != y.GetType().Name)
|
||
{
|
||
return false;
|
||
}
|
||
if (x.EntityTrain.Speed != y.EntityTrain.Speed)
|
||
{
|
||
return false;
|
||
}
|
||
if (x.EntityTrain.Weight != y.EntityTrain.Weight)
|
||
{
|
||
return false;
|
||
}
|
||
if (x.EntityTrain.MainColor != y.EntityTrain.MainColor)
|
||
{
|
||
return false;
|
||
}
|
||
if (x is DrawingMonorail && y is DrawingMonorail)
|
||
{
|
||
EntityMonorail newX = (EntityMonorail)x.EntityTrain;
|
||
EntityMonorail newY = (EntityMonorail)y.EntityTrain;
|
||
if (newX.AdditionalColor != newY.AdditionalColor)
|
||
{
|
||
return false;
|
||
}
|
||
if (newX.Wheels != newY.Wheels)
|
||
{
|
||
return false;
|
||
}
|
||
if (newX.Rail != newY.Rail)
|
||
{
|
||
return false;
|
||
}
|
||
if (newX.SecondСarriage != newY.SecondСarriage)
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public int GetHashCode([DisallowNull] DrawingTrain? obj)
|
||
{
|
||
return obj.GetHashCode();
|
||
}
|
||
}
|