53 lines
2.0 KiB
C#
53 lines
2.0 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using WarmlyLocomotive.DrawningObjects;
|
|
using WarmlyLocomotive.Entities;
|
|
|
|
namespace WarmlyLocomotive
|
|
{
|
|
internal class DrawingWarmlyLocomotiveEqutables : IEqualityComparer<DrawningWarmlyLocomotive?>
|
|
{
|
|
public bool Equals(DrawningWarmlyLocomotive? x, DrawningWarmlyLocomotive? y)
|
|
{
|
|
if (x == null || x.EntityWarmlyLocomotive == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(x));
|
|
}
|
|
if (y == null || y.EntityWarmlyLocomotive == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(y));
|
|
}
|
|
if (x.GetType().Name != y.GetType().Name)
|
|
{
|
|
return false;
|
|
}
|
|
if (x.EntityWarmlyLocomotive.Speed != y.EntityWarmlyLocomotive.Speed)
|
|
{
|
|
return false;
|
|
}
|
|
if (x.EntityWarmlyLocomotive.Weight != y.EntityWarmlyLocomotive.Weight)
|
|
{
|
|
return false;
|
|
}
|
|
if (x.EntityWarmlyLocomotive.BodyColor != y.EntityWarmlyLocomotive.BodyColor)
|
|
{
|
|
return false;
|
|
}
|
|
if (x is DrawningWarmlyLocomotiveWithTrumpet && y is DrawningWarmlyLocomotiveWithTrumpet)
|
|
{
|
|
EntityWarmlyLocomotiveWithTrumpet EntityX = (EntityWarmlyLocomotiveWithTrumpet)x.EntityWarmlyLocomotive;
|
|
EntityWarmlyLocomotiveWithTrumpet EntityY = (EntityWarmlyLocomotiveWithTrumpet)y.EntityWarmlyLocomotive;
|
|
if (EntityX.Trumpet != EntityY.Trumpet)
|
|
return false;
|
|
if (EntityX.Luggage != EntityY.Luggage)
|
|
return false;
|
|
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public int GetHashCode([DisallowNull] DrawningWarmlyLocomotive? obj)
|
|
{
|
|
return obj.GetHashCode();
|
|
}
|
|
}
|
|
} |