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
12
14 {
15 _hcp = hashCodeProvider;
17 }
18
19 public new bool Equals(object a, object b)
20 {
21 return Compare(a, b) == 0;
22 }
23
24 public int Compare(object a, object b)
25 {
26 if (a == b)
27 {
28 return 0;
29 }
30 if (a == null)
31 {
32 return -1;
33 }
34 if (b == null)
35 {
36 return 1;
37 }
38 if (_comparer != null)
39 {
40 return _comparer.Compare(a, b);
41 }
42 if (a is IComparable comparable)
43 {
44 return comparable.CompareTo(b);
45 }
47 }
48
49 public int GetHashCode(object obj)
50 {
51 if (obj == null)
52 {
53 throw new ArgumentNullException("obj");
54 }
55 if (_hcp == null)
56 {
57 return obj.GetHashCode();
58 }
59 return _hcp.GetHashCode(obj);
60 }
61}
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)