This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
1,741 additions
and
845 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/Common/tests/System/Collections/DelegateEqualityComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace System.Collections.Tests | ||
{ | ||
internal sealed class DelegateEqualityComparer<T> : IEqualityComparer<T>, IEqualityComparer | ||
{ | ||
private readonly Func<T, T, bool> _equals; | ||
private readonly Func<T, int> _getHashCode; | ||
private readonly Func<object, object, bool> _objectEquals; | ||
private readonly Func<object, int> _objectGetHashCode; | ||
|
||
public DelegateEqualityComparer( | ||
Func<T, T, bool> equals = null, | ||
Func<T, int> getHashCode = null, | ||
Func<object, object, bool> objectEquals = null, | ||
Func<object, int> objectGetHashCode = null) | ||
{ | ||
_equals = equals ?? ((x, y) => { throw new NotImplementedException(); }); | ||
_getHashCode = getHashCode ?? (obj => { throw new NotImplementedException(); }); | ||
_objectEquals = objectEquals ?? ((x, y) => { throw new NotImplementedException(); }); | ||
_objectGetHashCode = objectGetHashCode ?? (obj => { throw new NotImplementedException(); }); | ||
} | ||
|
||
public bool Equals(T x, T y) => _equals(x, y); | ||
|
||
public int GetHashCode(T obj) => _getHashCode(obj); | ||
|
||
bool IEqualityComparer.Equals(object x, object y) => _objectEquals(x, y); | ||
|
||
int IEqualityComparer.GetHashCode(object obj) => _objectGetHashCode(obj); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.