It is sometimes desirable to wrap other comparers with a Nito.Comparers comparer that just forwards to the underlying comparer. This brings the benefit of not throwing when GetHashCode(null) is called (see #13). We could make this wrapping easier.
Counterpoint: this wrapping makes it easy to treat an IComparer<T> as though it were an IEqualityComparer<T> (since the wrapper is an IFullComparer<T>). Currently, this would cause a runtime error if GetHashCode is used without being implemented (see https://github.com/StephenCleary/Comparers/wiki/Pitfalls). By making the wrapping easier, this pitfall is more exposed. However, it probably will remain a rare occurrence.
Possible syntax options:
Simple extension method: StringComparer.Ordinal.NormalizeNullHandling(). Not too wild about the naming.
Make the delegate in SelectBy/EquateBy optional (default to the identity function): ComparerBuilder.For<string>().CompareBy(StringComparer.Ordinal). Makes it clear that this is a Nito comparer, but seems pretty verbose.
It is sometimes desirable to wrap other comparers with a
Nito.Comparers
comparer that just forwards to the underlying comparer. This brings the benefit of not throwing whenGetHashCode(null)
is called (see #13). We could make this wrapping easier.Counterpoint: this wrapping makes it easy to treat an
IComparer<T>
as though it were anIEqualityComparer<T>
(since the wrapper is anIFullComparer<T>
). Currently, this would cause a runtime error ifGetHashCode
is used without being implemented (see https://github.com/StephenCleary/Comparers/wiki/Pitfalls). By making the wrapping easier, this pitfall is more exposed. However, it probably will remain a rare occurrence.Possible syntax options:
StringComparer.Ordinal.NormalizeNullHandling()
. Not too wild about the naming.SelectBy
/EquateBy
optional (default to the identity function):ComparerBuilder.For<string>().CompareBy(StringComparer.Ordinal)
. Makes it clear that this is aNito
comparer, but seems pretty verbose.