Создание класса DrawiningLocomotiveEqutables

This commit is contained in:
Андрей Байгулов 2023-12-24 14:25:05 +04:00
parent eaefd63d01
commit d0842fc00e

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.Entities;
using System.Diagnostics.CodeAnalysis;
namespace ProjectElectricLocomotive.Generics
{
internal class DrawingLocomotiveEqutables : IEqualityComparer<DrawingLocomotive?>
{
public bool Equals(DrawingLocomotive? x, DrawingLocomotive? y)
{
if (x == null || x.EntityLocomotive == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityLocomotive == null)
{
throw new ArgumentNullException(nameof(y));
}
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 DrawingElectricLocomotive && y is DrawingElectricLocomotive)
{
// TODO доделать логику сравнения дополнительных параметров
}
return true;
}
public int GetHashCode([DisallowNull] DrawingLocomotive obj)
{
return obj.GetHashCode();
}
}
}