For an object with properties A, B, C, D, StartDate and EndDate if I wanted to implement something where any two objects are equal if they have identical A, B and C and overlapping date range, how would that be done?
I have tried creating an EqualityComparer like so
public override bool Equals(RateItem x, RateItem y)
{
bool equal = true;
if ((x.A != y.A || x.B != y.B || x.C != y.C ||
(x.StartDate < y.StartDate && x.EndDate <= y.StartDate) ||
(x.StartDate > y.StartDate && y.EndDate <= x.StartDate)))
{ equal = false; }
return equal;
}
But it seems lots of places in the framework ignore Equals and use GetHashCode and the documentation is not clear on that at all. When I go to implement GetHashCode I don't know how to make the HashCodes turn out the same without ignoring the dates.
To make it a little more concrete this has to do with project management and rates. I want to implement a business rule that the same person on the same project in the same role can't have to different rates during the same time period. So Bob on Project DeathMarch in the role of DBA can only have one effective bill rate at any given time to log his time. If he needed to log some hours in the role of QA analyst at a different rate during the same time period that is OK. This is a massive pre-existing system so changing the domain object structure is not an option.