diff --git a/AntiAirCraftGun/AntiAirCraftGun/Generics/DrawingAntiAirCraftGunEqutables.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/DrawingAntiAirCraftGunEqutables.cs new file mode 100644 index 0000000..5c866e8 --- /dev/null +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/DrawingAntiAirCraftGunEqutables.cs @@ -0,0 +1,59 @@ +using AntiAircraftGun.DrawingObjects; +using AntiAircraftGun.Enitites; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun.Generics +{ + internal class DrawingAntiAirCraftGunEqutables : IEqualityComparer + { + public bool Equals(BaseDrawingAntiAirCraftGun? x, BaseDrawingAntiAirCraftGun? y) + { + if (x == null || x.AntiAirСraftGun == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.AntiAirСraftGun == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.GetType().Name != y.GetType().Name) + { + return false; + } + if (x.AntiAirСraftGun.Speed != y.AntiAirСraftGun.Speed) + { + return false; + } + if (x.AntiAirСraftGun.Weight != y.AntiAirСraftGun.Weight) + { + return false; + } + if (x.AntiAirСraftGun.BodyColor != y.AntiAirСraftGun.BodyColor) + { + return false; + } + if (x is AdvancedDrawingAntiAirCraftGun && y is AdvancedDrawingAntiAirCraftGun) + { + EntityAdvancedAntiAirCraftGun EntityX = (EntityAdvancedAntiAirCraftGun)x.AntiAirСraftGun; + EntityAdvancedAntiAirCraftGun EntityY = (EntityAdvancedAntiAirCraftGun)y.AntiAirСraftGun; + if (EntityX.Radar != EntityY.Radar) + return false; + if (EntityX.Rocket != EntityY.Rocket) + return false; + if (EntityX.DopColor != EntityY.DopColor) + return false; + } + return true; + } + + public int GetHashCode([DisallowNull] BaseDrawingAntiAirCraftGun obj) + { + return obj.GetHashCode(); + } + } +}