Implement IEquatable for sort and filter terms, closes #38

This commit is contained in:
Biarity 2018-11-16 18:23:45 +10:00
parent 3eaff4add4
commit 2d5fc0d232
2 changed files with 19 additions and 3 deletions

View File

@ -4,7 +4,7 @@ using System.Text.RegularExpressions;
namespace Sieve.Models namespace Sieve.Models
{ {
public class FilterTerm : IFilterTerm public class FilterTerm : IFilterTerm, IEquatable<FilterTerm>
{ {
public FilterTerm() { } public FilterTerm() { }
@ -76,5 +76,13 @@ namespace Sieve.Models
} }
public bool OperatorIsCaseInsensitive { get; private set; } public bool OperatorIsCaseInsensitive { get; private set; }
public bool Equals(FilterTerm other)
{
return Names.SequenceEqual(other.Names)
&& Values.SequenceEqual(other.Values)
&& Operator == other.Operator;
}
} }
} }

View File

@ -1,6 +1,8 @@
namespace Sieve.Models using System;
namespace Sieve.Models
{ {
public class SortTerm : ISortTerm public class SortTerm : ISortTerm, IEquatable<SortTerm>
{ {
public SortTerm() { } public SortTerm() { }
@ -17,5 +19,11 @@
public string Name => (_sort.StartsWith("-")) ? _sort.Substring(1) : _sort; public string Name => (_sort.StartsWith("-")) ? _sort.Substring(1) : _sort;
public bool Descending => _sort.StartsWith("-"); public bool Descending => _sort.StartsWith("-");
public bool Equals(SortTerm other)
{
return Name == other.Name
&& Descending == other.Descending;
}
} }
} }