Skip to content

Commit 8f9b29c

Browse files
committed
Implemented IEquatable.
1 parent af38087 commit 8f9b29c

File tree

1 file changed

+129
-8
lines changed

1 file changed

+129
-8
lines changed

ReClass.NET/MemoryScanner/ScanResult.cs

Lines changed: 129 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics.Contracts;
3+
using System.Linq;
34
using System.Text;
45

56
namespace ReClassNET.MemoryScanner
@@ -13,7 +14,7 @@ public abstract class ScanResult
1314
public abstract ScanResult Clone();
1415
}
1516

16-
public class ByteScanResult : ScanResult
17+
public class ByteScanResult : ScanResult, IEquatable<ByteScanResult>
1718
{
1819
public override ScanValueType ValueType => ScanValueType.Byte;
1920

@@ -28,9 +29,24 @@ public override ScanResult Clone()
2829
{
2930
return new ByteScanResult(Value) { Address = Address };
3031
}
32+
33+
public override bool Equals(object obj)
34+
{
35+
return Equals(obj as ByteScanResult);
36+
}
37+
38+
public bool Equals(ByteScanResult other)
39+
{
40+
return other != null && Address == other.Address && Value == other.Value;
41+
}
42+
43+
public override int GetHashCode()
44+
{
45+
return Address.GetHashCode() * 19 + Value.GetHashCode();
46+
}
3147
}
3248

33-
public class ShortScanResult : ScanResult
49+
public class ShortScanResult : ScanResult, IEquatable<ShortScanResult>
3450
{
3551
public override ScanValueType ValueType => ScanValueType.Short;
3652

@@ -45,9 +61,24 @@ public override ScanResult Clone()
4561
{
4662
return new ShortScanResult(Value) { Address = Address };
4763
}
64+
65+
public override bool Equals(object obj)
66+
{
67+
return Equals(obj as ShortScanResult);
68+
}
69+
70+
public bool Equals(ShortScanResult other)
71+
{
72+
return other != null && Address == other.Address && Value == other.Value;
73+
}
74+
75+
public override int GetHashCode()
76+
{
77+
return Address.GetHashCode() * 19 + Value.GetHashCode();
78+
}
4879
}
4980

50-
public class IntegerScanResult : ScanResult
81+
public class IntegerScanResult : ScanResult, IEquatable<IntegerScanResult>
5182
{
5283
public override ScanValueType ValueType => ScanValueType.Integer;
5384

@@ -62,9 +93,24 @@ public override ScanResult Clone()
6293
{
6394
return new IntegerScanResult(Value) { Address = Address };
6495
}
96+
97+
public override bool Equals(object obj)
98+
{
99+
return Equals(obj as IntegerScanResult);
100+
}
101+
102+
public bool Equals(IntegerScanResult other)
103+
{
104+
return other != null && Address == other.Address && Value == other.Value;
105+
}
106+
107+
public override int GetHashCode()
108+
{
109+
return Address.GetHashCode() * 19 + Value.GetHashCode();
110+
}
65111
}
66112

67-
public class LongScanResult : ScanResult
113+
public class LongScanResult : ScanResult, IEquatable<LongScanResult>
68114
{
69115
public override ScanValueType ValueType => ScanValueType.Long;
70116

@@ -79,9 +125,24 @@ public override ScanResult Clone()
79125
{
80126
return new LongScanResult(Value) { Address = Address };
81127
}
128+
129+
public override bool Equals(object obj)
130+
{
131+
return Equals(obj as LongScanResult);
132+
}
133+
134+
public bool Equals(LongScanResult other)
135+
{
136+
return other != null && Address == other.Address && Value == other.Value;
137+
}
138+
139+
public override int GetHashCode()
140+
{
141+
return Address.GetHashCode() * 19 + Value.GetHashCode();
142+
}
82143
}
83144

84-
public class FloatScanResult : ScanResult
145+
public class FloatScanResult : ScanResult, IEquatable<FloatScanResult>
85146
{
86147
public override ScanValueType ValueType => ScanValueType.Float;
87148

@@ -96,9 +157,24 @@ public override ScanResult Clone()
96157
{
97158
return new FloatScanResult(Value) { Address = Address };
98159
}
160+
161+
public override bool Equals(object obj)
162+
{
163+
return Equals(obj as FloatScanResult);
164+
}
165+
166+
public bool Equals(FloatScanResult other)
167+
{
168+
return other != null && Address == other.Address && Value == other.Value;
169+
}
170+
171+
public override int GetHashCode()
172+
{
173+
return Address.GetHashCode() * 19 + Value.GetHashCode();
174+
}
99175
}
100176

101-
public class DoubleScanResult : ScanResult
177+
public class DoubleScanResult : ScanResult, IEquatable<DoubleScanResult>
102178
{
103179
public override ScanValueType ValueType => ScanValueType.Double;
104180

@@ -113,9 +189,24 @@ public override ScanResult Clone()
113189
{
114190
return new DoubleScanResult(Value) { Address = Address };
115191
}
192+
193+
public override bool Equals(object obj)
194+
{
195+
return Equals(obj as DoubleScanResult);
196+
}
197+
198+
public bool Equals(DoubleScanResult other)
199+
{
200+
return other != null && Address == other.Address && Value == other.Value;
201+
}
202+
203+
public override int GetHashCode()
204+
{
205+
return Address.GetHashCode() * 19 + Value.GetHashCode();
206+
}
116207
}
117208

118-
public class ArrayOfBytesScanResult : ScanResult
209+
public class ArrayOfBytesScanResult : ScanResult, IEquatable<ArrayOfBytesScanResult>
119210
{
120211
public override ScanValueType ValueType => ScanValueType.ArrayOfBytes;
121212

@@ -132,9 +223,24 @@ public override ScanResult Clone()
132223
{
133224
return new ArrayOfBytesScanResult(Value) { Address = Address };
134225
}
226+
227+
public override bool Equals(object obj)
228+
{
229+
return Equals(obj as ArrayOfBytesScanResult);
230+
}
231+
232+
public bool Equals(ArrayOfBytesScanResult other)
233+
{
234+
return other != null && Address == other.Address && Enumerable.SequenceEqual(Value, other.Value);
235+
}
236+
237+
public override int GetHashCode()
238+
{
239+
return Address.GetHashCode() * 19 + Value.GetHashCode();
240+
}
135241
}
136242

137-
public class StringScanResult : ScanResult
243+
public class StringScanResult : ScanResult, IEquatable<StringScanResult>
138244
{
139245
public override ScanValueType ValueType => ScanValueType.String;
140246

@@ -155,5 +261,20 @@ public override ScanResult Clone()
155261
{
156262
return new StringScanResult(Value, Encoding) { Address = Address };
157263
}
264+
265+
public override bool Equals(object obj)
266+
{
267+
return Equals(obj as StringScanResult);
268+
}
269+
270+
public bool Equals(StringScanResult other)
271+
{
272+
return other != null && Address == other.Address && Value == other.Value && Encoding.Equals(other.Encoding);
273+
}
274+
275+
public override int GetHashCode()
276+
{
277+
return Address.GetHashCode() * 19 + Value.GetHashCode() * 19 + Encoding.GetHashCode();
278+
}
158279
}
159280
}

0 commit comments

Comments
 (0)