Skip to content

Commit bba6fe6

Browse files
committed
#153 - ISymbolId interface
1 parent ca728b9 commit bba6fe6

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace HydraScript.Domain.IR;
2+
3+
public interface ISymbolId<out TSymbol> : IEquatable<ISymbolId<ISymbol>>
4+
where TSymbol : class, ISymbol;

src/Domain/HydraScript.Domain.IR/SymbolId.cs

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

3-
public abstract class SymbolId : IEquatable<SymbolId>
3+
public abstract class SymbolId<TSymbol> : ISymbolId<TSymbol>
4+
where TSymbol : class, ISymbol
45
{
56
protected abstract string Value { get; }
67

7-
public bool Equals(SymbolId? other)
8-
{
9-
if (other is null) return false;
10-
if (ReferenceEquals(this, other)) return true;
11-
return Value == other.Value;
12-
}
8+
public bool Equals(ISymbolId<ISymbol>? other) =>
9+
Value == other?.ToString();
1310

1411
public override bool Equals(object? obj)
1512
{
16-
if (obj is null) return false;
17-
if (ReferenceEquals(this, obj)) return true;
18-
if (obj.GetType() != GetType()) return false;
19-
return Equals((SymbolId)obj);
13+
if (obj is ISymbolId<ISymbol> other)
14+
return Equals(other);
15+
return false;
2016
}
2117

2218
public override int GetHashCode() => Value.GetHashCode();

0 commit comments

Comments
 (0)