public bool Equals(Product x, Product y) { // This gives an "early out" for equal references or the case where one reference is null. return(PartialComparer.ReferenceEquals(x, y) ?? x.Name == y.Name && x.Popularity == y.Popularity && x.Price == y.Price); }
public int Compare(Product first, Product second) { return(PartialComparer.ReferenceCompare(first, second) ?? // Reverse comparison of popularity to sort descending PartialComparer.Compare(second.Popularity, first.Popularity) ?? PartialComparer.Compare(first.Price, second.Price) ?? PartialComparer.Compare(first.Name, second.Name) ?? 0); }