From 7fffd91c9b69c86b0784067d33e7e1b5559ffc85 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 23 Mar 2022 17:56:46 +0300 Subject: Position class Equals method override --- src/PriceListTools/Position.cs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/PriceListTools/Position.cs') diff --git a/src/PriceListTools/Position.cs b/src/PriceListTools/Position.cs index 0863642..34b7b93 100644 --- a/src/PriceListTools/Position.cs +++ b/src/PriceListTools/Position.cs @@ -1,6 +1,8 @@ -namespace RehauSku.PriceListTools +using System.Linq; + +namespace RehauSku.PriceListTools { - public class Position + public class Position { public string Group { get; private set; } public string Sku { get; private set; } @@ -12,5 +14,29 @@ Sku = sku; Name = name; } + + public override bool Equals(object obj) + { + if (obj as Position == null) + return false; + + Position other = obj as Position; + + return Group == other.Group && + Sku == other.Sku && + Name == other.Name; + } + + public override int GetHashCode() + { + string[] properties = new[] + { + Group, + Sku, + Name + }; + + return properties.Where(p => p != null).Sum(p => p.GetHashCode()); + } } } \ No newline at end of file -- cgit v1.2.3