Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 4fa3efd

Browse files
author
Yuncong Zhang
committed
Fix ValueKey comparison.
1 parent 6959ee6 commit 4fa3efd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Runtime/foundation/key.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ protected Key() {
99
public static Key key(string value) {
1010
return new ValueKey<string>(value);
1111
}
12+
13+
public virtual bool Equals(Key other) {
14+
return base.Equals(other);
15+
}
16+
17+
public static bool operator ==(Key left, Key right) {
18+
return Equals(left, right);
19+
}
20+
21+
public static bool operator !=(Key left, Key right) {
22+
return !Equals(left, right);
23+
}
1224
}
1325

1426
public abstract class LocalKey : Key {
@@ -23,6 +35,24 @@ public ValueKey(T value) {
2335

2436
public readonly T value;
2537

38+
public override bool Equals(Key other) {
39+
if (ReferenceEquals(null, other)) {
40+
return false;
41+
}
42+
43+
if (ReferenceEquals(this, other)) {
44+
return true;
45+
}
46+
47+
if (other.GetType() != typeof(ValueKey<T>)) {
48+
return false;
49+
}
50+
51+
ValueKey<T> valueKey = (ValueKey<T>) other;
52+
53+
return this.Equals(valueKey);
54+
}
55+
2656
public bool Equals(ValueKey<T> other) {
2757
if (ReferenceEquals(null, other)) {
2858
return false;

0 commit comments

Comments
 (0)