コード例 #1
0
        /// <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))
コード例 #2
0
 /// <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);
コード例 #3
0
        /// <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);
        }
コード例 #4
0
 /// <inheritdoc cref="GetHashCode(object,ValuerChainer)"/>
 protected abstract int GetHashCode(T item, ValuerChainer valuer);
コード例 #5
0
 /// <inheritdoc/>
 protected sealed override int GetHashCode(object item, ValuerChainer valuer)
 {
     return(GetHashCode((T)item, valuer));
 }
コード例 #6
0
 /// <inheritdoc cref="Compare(object,object,ValuerChainer)"/>
 protected abstract IEnumerable <Difference> Compare(T expected, T actual, ValuerChainer valuer);
コード例 #7
0
 /// <inheritdoc/>
 protected sealed override IEnumerable <Difference> Compare(object expected, object actual, ValuerChainer valuer)
 {
     return(Compare((T)expected, (T)actual, valuer));
 }
コード例 #8
0
 /// <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);
     }
 }