-
Notifications
You must be signed in to change notification settings - Fork 543
/
ComparerHelpersImpl.cs
117 lines (96 loc) · 2.74 KB
/
ComparerHelpersImpl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using Cosmos.Debug.Kernel;
using IL2CPU.API.Attribs;
using System;
using System.Collections.Generic;
namespace Cosmos.Core_Plugs.System.Collections.Generic
{
[Plug("System.Collections.Generic.ComparerHelpers, System.Private.CoreLib")]
public static class ComparerHelpersImpl
{
private static readonly Debugger mDebugger = new Debugger("Core", "ComparerHelpersImpl");
public static object CreateDefaultComparer(Type aType)
{
Debugger.DoBochsBreak();
if (aType == typeof(string))
{
return new StringComparer();
}
return null;
}
public static object CreateDefaultEqualityComparer(Type aType)
{
Debugger.DoBochsBreak();
if (aType == typeof(string))
{
return new StringEqualityComparer();
}
if (aType == typeof(char))
{
return new CharEqualityComparer();
}
if (aType == typeof(int))
{
return new Int32EqualityComparer();
}
if (aType == typeof(byte))
{
return new ByteEqualityComparer();
}
// TODO: Nullable<>
// TODO: Enum (Comparer is special to avoid boxing)
mDebugger.Send($"No EqualityComparer for type {aType}");
return null;
}
}
public class StringComparer : Comparer<string>
{
public override int Compare(string x, string y)
{
throw new NotImplementedException();
}
}
public class StringEqualityComparer : EqualityComparer<string>
{
public override bool Equals(string x, string y)
{
return String.Equals(x, y);
}
public override int GetHashCode(string obj)
{
return obj.GetHashCode();
}
}
public class CharEqualityComparer : EqualityComparer<char>
{
public override bool Equals(char x, char y)
{
return x == y;
}
public override int GetHashCode(char val)
{
return val.GetHashCode();
}
}
public class ByteEqualityComparer : EqualityComparer<byte>
{
public override bool Equals(byte x, byte y)
{
return x == y;
}
public override int GetHashCode(byte val)
{
return val.GetHashCode();
}
}
public class Int32EqualityComparer : EqualityComparer<int>
{
public override bool Equals(int x, int y)
{
return x == y;
}
public override int GetHashCode(int val)
{
return val.GetHashCode();
}
}
}