Skip to content

Commit 9c2e348

Browse files
committed
#202 - type use iequatable
1 parent c46d4f1 commit 9c2e348

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

src/Domain/HydraScript.Domain.IR/Types/Any.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace HydraScript.Domain.IR.Types;
55
[ExcludeFromCodeCoverage]
66
public class Any() : Type("any")
77
{
8-
public override bool Equals(object? obj) => true;
8+
public override bool Equals(Type? obj) => true;
99

1010
public override int GetHashCode() => "any".GetHashCode();
1111
}

src/Domain/HydraScript.Domain.IR/Types/ArrayType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public override void ResolveReference(
1515
Type.ResolveReference(reference, refId, visited);
1616
}
1717

18-
public override bool Equals(object? obj)
18+
public override bool Equals(Type? obj)
1919
{
2020
if (obj is ArrayType that)
2121
return Equals(Type, that.Type);

src/Domain/HydraScript.Domain.IR/Types/NullType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace HydraScript.Domain.IR.Types;
22

33
public class NullType() : Type("null")
44
{
5-
public override bool Equals(object? obj) =>
5+
public override bool Equals(Type? obj) =>
66
obj is ObjectType or NullableType or NullType or Any;
77

88
public override int GetHashCode() =>

src/Domain/HydraScript.Domain.IR/Types/NullableType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public override void ResolveReference(
1515
Type.ResolveReference(reference, refId, visited);
1616
}
1717

18-
public override bool Equals(object? obj)
18+
public override bool Equals(Type? obj)
1919
{
2020
if (obj is NullableType that)
2121
return Equals(Type, that.Type);
2222

23-
return obj is NullType or Any || (obj is Type type && type.Equals(Type));
23+
return obj is NullType or Any || (obj is not null && obj.Equals(Type));
2424
}
2525

2626
public override int GetHashCode() =>

src/Domain/HydraScript.Domain.IR/Types/ObjectType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public override void ResolveReference(
6969
this[key]!.ResolveReference(reference, refId, visited);
7070
}
7171

72-
public override bool Equals(object? obj)
72+
public override bool Equals(Type? obj)
7373
{
7474
if (obj is ObjectType that)
7575
return ReferenceEquals(this, that) ||

src/Domain/HydraScript.Domain.IR/Types/Type.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace HydraScript.Domain.IR.Types;
22

3-
public class Type
3+
public class Type : IEquatable<Type>
44
{
55
private readonly string _name = string.Empty;
66

@@ -18,14 +18,16 @@ public virtual void ResolveReference(
1818
{
1919
}
2020

21-
public override bool Equals(object? obj) =>
21+
public virtual bool Equals(Type? obj) =>
2222
obj switch
2323
{
2424
Any => true,
25-
Type that => _name == that._name,
25+
not null => _name == obj._name,
2626
_ => false
2727
};
2828

29+
public override bool Equals(object? obj) => Equals(obj as Type);
30+
2931
public override int GetHashCode() =>
3032
_name.GetHashCode();
3133

0 commit comments

Comments
 (0)