diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2022-03-23 17:56:46 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2022-03-23 17:56:46 +0300 |
commit | 7fffd91c9b69c86b0784067d33e7e1b5559ffc85 (patch) | |
tree | be4c3885314daa05593e89d8a815c2366c9ab943 /src/PriceListTools/Position.cs | |
parent | 5dcc91e4a13e35588a8b0dfc8fda391076122a0b (diff) |
Position class Equals method override
Diffstat (limited to 'src/PriceListTools/Position.cs')
-rw-r--r-- | src/PriceListTools/Position.cs | 30 |
1 files changed, 28 insertions, 2 deletions
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 |