예제 #1
0
 /// <summary>
 /// Tries to convert the specified <paramref name="comparer"/> to a strongly typed <see cref="SetEqualityComparer{T}"/>.
 /// </summary>
 /// <param name="comparer">The comparer to convert to a <see cref="SetEqualityComparer{T}"/>, if possible.</param>
 /// <param name="equalityComparer">The result <see cref="SetEqualityComparer{T}"/> of the conversion.</param>
 /// <returns><c>true</c> if the conversion was successful; otherwise, <c>false</c>.</returns>
 public static bool TryGetSetEqualityComparer(IEqualityComparer comparer, out SetEqualityComparer <T> equalityComparer)
 {
     // StructuralEqualityComparer is too "dumb" to resolve generic collections.
     // This is done on purpose for performance reasons. Sets
     // must convert the comparison mode to the resolved SetEqualityComparer<T>
     // to prevent StructuralEqualityComparer from needing to use reflection to do it.
     if (comparer is StructuralEqualityComparer seComparer)
     {
         if (seComparer.Equals(StructuralEqualityComparer.Default))
         {
             equalityComparer = Default;
         }
         else
         {
             equalityComparer = Aggressive;
         }
         return(true);
     }
     else if (comparer is SetEqualityComparer <T> setComparer)
     {
         equalityComparer = setComparer;
         return(true);
     }
     equalityComparer = null;
     return(false);
 }
예제 #2
0
 public virtual int GetHashCode(IEqualityComparer comparer)
 => SetEqualityComparer <T> .GetHashCode(this, comparer);
예제 #3
0
 public virtual bool Equals(object?other, IEqualityComparer comparer)
 => SetEqualityComparer <T> .Equals(this, other, comparer);