From 2d5fc0d2329a1d9d72b80b990e2ca655070be549 Mon Sep 17 00:00:00 2001 From: Biarity Date: Fri, 16 Nov 2018 18:23:45 +1000 Subject: [PATCH] Implement IEquatable for sort and filter terms, closes #38 --- Sieve/Models/FilterTerm.cs | 10 +++++++++- Sieve/Models/SortTerm.cs | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Sieve/Models/FilterTerm.cs b/Sieve/Models/FilterTerm.cs index 17fdf9c..ef2b71e 100644 --- a/Sieve/Models/FilterTerm.cs +++ b/Sieve/Models/FilterTerm.cs @@ -4,7 +4,7 @@ using System.Text.RegularExpressions; namespace Sieve.Models { - public class FilterTerm : IFilterTerm + public class FilterTerm : IFilterTerm, IEquatable { public FilterTerm() { } @@ -76,5 +76,13 @@ namespace Sieve.Models } public bool OperatorIsCaseInsensitive { get; private set; } + + public bool Equals(FilterTerm other) + { + return Names.SequenceEqual(other.Names) + && Values.SequenceEqual(other.Values) + && Operator == other.Operator; + } + } } diff --git a/Sieve/Models/SortTerm.cs b/Sieve/Models/SortTerm.cs index 4d819b6..9299966 100644 --- a/Sieve/Models/SortTerm.cs +++ b/Sieve/Models/SortTerm.cs @@ -1,6 +1,8 @@ -namespace Sieve.Models +using System; + +namespace Sieve.Models { - public class SortTerm : ISortTerm + public class SortTerm : ISortTerm, IEquatable { public SortTerm() { } @@ -17,5 +19,11 @@ public string Name => (_sort.StartsWith("-")) ? _sort.Substring(1) : _sort; public bool Descending => _sort.StartsWith("-"); + + public bool Equals(SortTerm other) + { + return Name == other.Name + && Descending == other.Descending; + } } }