/// <param name="item">Object to generate a code for.</param> /// <param name="chainer">Handles callback behavior for child values.</param> /// <inheritdoc cref="GetHashCode(object)"/> private int GetHashCode(object item, ValuerChainer chainer) { (bool, int)result = _hints .Select(h => h.TryGetHashCode(item, chainer)) .FirstOrDefault(r => r.Item1); if (!result.Equals(default))
/// <summary>Tries to calculate a hash code for <paramref name="item"/> based upon value.</summary> /// <param name="item">Object to generate a code for.</param> /// <param name="valuer">Handles callback behavior for child values.</param> /// <returns> /// (<c>true</c>, generated hash) if successful; /// (<c>false</c>, <c>0</c>) otherwise. /// </returns> internal (bool, int) TryGetHashCode(object item, ValuerChainer valuer) { if (Supports(item, item, valuer)) { return(true, GetHashCode(item, valuer)); } else { return(false, default);
/// <inheritdoc/> protected sealed override bool Supports(object expected, object actual, ValuerChainer valuer) { if (expected == null) { throw new ArgumentNullException(nameof(expected)); } if (actual == null) { throw new ArgumentNullException(nameof(actual)); } if (valuer == null) { throw new ArgumentNullException(nameof(valuer)); } return(expected is T && actual is T); }
/// <inheritdoc cref="GetHashCode(object,ValuerChainer)"/> protected abstract int GetHashCode(T item, ValuerChainer valuer);
/// <inheritdoc/> protected sealed override int GetHashCode(object item, ValuerChainer valuer) { return(GetHashCode((T)item, valuer)); }
/// <inheritdoc cref="Compare(object,object,ValuerChainer)"/> protected abstract IEnumerable <Difference> Compare(T expected, T actual, ValuerChainer valuer);
/// <inheritdoc/> protected sealed override IEnumerable <Difference> Compare(object expected, object actual, ValuerChainer valuer) { return(Compare((T)expected, (T)actual, valuer)); }
/// <summary> /// Tries to find the differences between <paramref name="expected"/> and <paramref name="actual"/>. /// </summary> /// <param name="expected">Object to compare with <paramref name="actual"/>.</param> /// <param name="actual">Potentially different object to compare against <paramref name="expected"/>.</param> /// <param name="valuer">Handles callback behavior for child values.</param> /// <returns> /// (<c>true</c>, found differences) if successful; /// (<c>false</c>, <c>null</c>) otherwise. /// </returns> internal (bool, IEnumerable <Difference>) TryCompare(object expected, object actual, ValuerChainer valuer) { if (Supports(expected, actual, valuer)) { return(true, Compare(expected, actual, valuer)); } else { return(false, null); } }