/// <summary> /// Returns a hash code for the specified object. /// </summary> /// <param name="obj">The object for which to return a hash code. This object may be <c>null</c>.</param> /// <returns>A hash code for the specified object.</returns> protected override int DoGetHashCode(T obj) { unchecked { var ret = (int)2166136261; ret += ComparerHelpers.GetHashCodeFromComparer(_source, obj); ret *= 16777619; ret += ComparerHelpers.GetHashCodeFromComparer(_secondSource, obj); ret *= 16777619; return(ret); } }
/// <summary> /// Returns a hash code for the specified object. /// </summary> /// <param name="obj">The object for which to return a hash code.</param> /// <returns>A hash code for the specified object.</returns> protected override int DoGetHashCode(IEnumerable <T> obj) { unchecked { var ret = (int)2166136261; foreach (var item in obj) { ret += ComparerHelpers.GetHashCodeFromComparer(_source, item); ret *= 16777619; } return(ret); } }
/// <summary> /// Returns a hash code for the specified object. /// </summary> /// <param name="obj">The object for which to return a hash code. This object may be <c>null</c>.</param> /// <returns>A hash code for the specified object.</returns> protected override int DoGetHashCode(T obj) { return(ComparerHelpers.GetHashCodeFromComparer(_source, obj)); }
/// <summary> /// Initializes a new instance of the <see cref="CompoundComparer<T>"/> class. /// </summary> /// <param name="source">The source comparer. If this is <c>null</c>, the default comparer is used.</param> /// <param name="secondSource">The second comparer. If this is <c>null</c>, the default comparer is used.</param> public CompoundComparer(IComparer <T>?source, IComparer <T>?secondSource) : base(source, null, true) { _secondSource = ComparerHelpers.NormalizeDefault(secondSource); _secondSourceGetHashCode = ComparerHelpers.ComparerGetHashCode(_secondSource); }
/// <summary> /// Initializes a new instance of the <see cref="SourceComparerBase<T, TSource>"/> class. /// </summary> /// <param name="source">The source comparer. If this is <c>null</c>, the default comparer is used.</param> /// <param name="getHashCode">The <c>GetHashCode</c> implementation to use. If this is <c>null</c>, this type will attempt to find <c>GetHashCode</c> on <paramref name="source"/>; if none is found, throws an exception.</param> /// <param name="specialNullHandling">A value indicating whether <c>null</c> values are passed to <see cref="EqualityComparerBase{T}.DoGetHashCode"/> and <see cref="ComparerBase{T}.DoCompare"/>. If <c>false</c>, then <c>null</c> values are considered less than any non-<c>null</c> values and are not passed to <see cref="EqualityComparerBase{T}.DoGetHashCode"/> nor <see cref="ComparerBase{T}.DoCompare"/>. This value is ignored if <typeparamref name="T"/> is a non-nullable type.</param> protected SourceComparerBase(IComparer <TSource>?source, Func <TSource, int>?getHashCode, bool specialNullHandling) : base(specialNullHandling) { Source = ComparerHelpers.NormalizeDefault(source); SourceGetHashCode = getHashCode ?? ComparerHelpers.ComparerGetHashCode(Source); }
/// <summary> /// Initializes a new instance of the <see cref="SourceComparerBase<T, TSource>"/> class. /// </summary> /// <param name="source">The source comparer. If this is <c>null</c>, the default comparer is used.</param> /// <param name="specialNullHandling">A value indicating whether <c>null</c> values are passed to <see cref="EqualityComparerBase{T}.DoGetHashCode"/> and <see cref="ComparerBase{T}.DoCompare"/>. If <c>false</c>, then <c>null</c> values are considered less than any non-<c>null</c> values and are not passed to <see cref="EqualityComparerBase{T}.DoGetHashCode"/> nor <see cref="ComparerBase{T}.DoCompare"/>.</param> protected SourceComparerBase(IComparer <TSource> source, bool specialNullHandling) : base(specialNullHandling) { _source = ComparerHelpers.NormalizeDefault(source); }
/// <summary> /// Initializes a new instance of the <see cref="CompoundComparer<T>"/> class. /// </summary> /// <param name="source">The source comparer. If this is <c>null</c>, the default comparer is used.</param> /// <param name="secondSource">The second comparer. If this is <c>null</c>, the default comparer is used.</param> public CompoundComparer(IComparer <T> source, IComparer <T> secondSource) : base(source, true) { _secondSource = ComparerHelpers.NormalizeDefault(secondSource); }