Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CompatibleComparer.cs
Go to the documentation of this file.
1namespace System.Collections;
2
3internal sealed class CompatibleComparer : IEqualityComparer
4{
5 private readonly IHashCodeProvider _hcp;
6
7 private readonly IComparer _comparer;
8
10 {
11 _hcp = hashCodeProvider;
13 }
14
15 public new bool Equals(object a, object b)
16 {
17 return Compare(a, b) == 0;
18 }
19
20 public int Compare(object a, object b)
21 {
22 if (a == b)
23 {
24 return 0;
25 }
26 if (a == null)
27 {
28 return -1;
29 }
30 if (b == null)
31 {
32 return 1;
33 }
34 if (_comparer != null)
35 {
36 return _comparer.Compare(a, b);
37 }
38 if (a is IComparable comparable)
39 {
40 return comparable.CompareTo(b);
41 }
43 }
44
45 public int GetHashCode(object obj)
46 {
47 if (obj == null)
48 {
49 throw new ArgumentNullException("obj");
50 }
51 if (_hcp == null)
52 {
53 return obj.GetHashCode();
54 }
55 return _hcp.GetHashCode(obj);
56 }
57}
new bool Equals(object a, object b)
CompatibleComparer(IHashCodeProvider hashCodeProvider, IComparer comparer)
static string Argument_ImplementIComparable
Definition SR.cs:34
Definition SR.cs:7
int Compare(object? x, object? y)