PIbd22_Kamcharova_K.A._Doub.../DoubleDeckerBus/Generic/DrawingBusEqutables.cs

58 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
using DoubleDeckerbus.Drawing;
using DoubleDeckerbus.Entities;
namespace DoubleDeckerbus.Generics
{
internal class DrawingBusEqutables : IEqualityComparer<DrawingBus?>
{
public bool Equals(DrawingBus? x, DrawingBus? y)
{
if (x == null && x.EntityBus == null)
throw new ArgumentNullException(nameof(x));
if (y == null && y.EntityBus == null)
throw new ArgumentNullException(nameof(y));
if ((x.GetType().Name != y.GetType().Name))
return false;
if (x.EntityBus.Speed != y.EntityBus.Speed)
return false;
if (x.EntityBus.Weight != y.EntityBus.Weight)
return false;
if (x.EntityBus.BodyColor != y.EntityBus.BodyColor)
return false;
if (x is DrawingDoubleDeckerbus && y is DrawingDoubleDeckerbus)
{
var xDoublebus = (EntityDoubleDeckerbus)x.EntityBus;
var yDoublebus = (EntityDoubleDeckerbus)y.EntityBus;
if (xDoublebus.AddColor != yDoublebus.AddColor)
return false;
if (xDoublebus.IsSecondFloor != yDoublebus.IsSecondFloor)
return false;
if (xDoublebus.IsStairs != yDoublebus.IsStairs)
return false;
}
return true;
}
public int GetHashCode([DisallowNull] DrawingBus? obj)
{
return obj.GetHashCode();
}
}
}