namespace Sharpen { using System.Collections.Generic; using System.Linq; public class SequenceEqualityComparer : EqualityComparer> { private static readonly SequenceEqualityComparer _default = new SequenceEqualityComparer(); private readonly IEqualityComparer _elementEqualityComparer = EqualityComparer.Default; public SequenceEqualityComparer() : this(null) { } public SequenceEqualityComparer(IEqualityComparer elementComparer) { _elementEqualityComparer = elementComparer ?? EqualityComparer.Default; } public new static SequenceEqualityComparer Default { get { return _default; } } public override bool Equals(IEnumerable x, IEnumerable y) { if (x == y) return true; if (x == null || y == null) return false; return x.SequenceEqual(y, _elementEqualityComparer); } public override int GetHashCode(IEnumerable obj) { if (obj == null) return 0; int hashCode = 1; foreach (T element in obj) hashCode = 31 * hashCode + _elementEqualityComparer.GetHashCode(element); return hashCode; } } }