From b5aeebf1323c15d82863822cdcf2292b84b5f811 Mon Sep 17 00:00:00 2001 From: YourDax Date: Mon, 11 Dec 2023 20:08:12 +0400 Subject: [PATCH] equtables.cs --- .../DrawingAntiAirCraftGunEqutables.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 AntiAirCraftGun/AntiAirCraftGun/Generics/DrawingAntiAirCraftGunEqutables.cs 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(); + } + } +}