PIbd-23_Vrazhkin_S_A_Electr.../lab1/DrawingObjects/DrawingLocomotivEqutables.cs

48 lines
1.5 KiB
C#
Raw Normal View History

2023-12-12 13:58:32 +04:00
using System.Diagnostics.CodeAnalysis;
namespace ElectricLocomotive;
public class DrawingLocomotivEqutables: IEqualityComparer<DrawingLocomotiv?>
{
public bool Equals(DrawingLocomotiv? x, DrawingLocomotiv? y)
{
if (x == null || x.EntityLocomotiv == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityLocomotiv == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityLocomotiv.Speed != y.EntityLocomotiv.Speed)
{
return false;
}
if (x.EntityLocomotiv.Weight != y.EntityLocomotiv.Weight)
{
return false;
}
if (x.EntityLocomotiv.ColorBody != y.EntityLocomotiv.ColorBody)
{
return false;
}
if (x is DrawingElectricLocomotiv && y is DrawingElectricLocomotiv)
{
EntityElectricLocomotiv EntityX = (EntityElectricLocomotiv)x.EntityLocomotiv;
EntityElectricLocomotiv EntityY = (EntityElectricLocomotiv)y.EntityLocomotiv;
if (EntityX.isBattery != EntityY.isBattery)
return false;
if (EntityX.isRoga != EntityY.isRoga)
return false;
}
return true;
}
public int GetHashCode([DisallowNull] DrawingLocomotiv obj)
{
return obj.GetHashCode();
}
}