Skip to content

Commit 07209a6

Browse files
committed
chore: fixes equals implementation
Signed-off-by: Vincent Biret <[email protected]>
1 parent 4965a7b commit 07209a6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Microsoft.OpenApi/Expressions/RuntimeExpression.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,29 @@ public static RuntimeExpression Build(string expression)
7878
/// </summary>
7979
public override int GetHashCode()
8080
{
81-
return Expression.GetHashCode();
81+
return StringComparer.Ordinal.GetHashCode(Expression);
8282
}
8383

8484
/// <summary>
8585
/// Equals implementation for IEquatable.
8686
/// </summary>
8787
public override bool Equals(object? obj)
8888
{
89-
return Equals(obj as RuntimeExpression);
89+
if (obj == null)
90+
{
91+
return false;
92+
}
93+
if (ReferenceEquals(this, obj))
94+
{
95+
return true;
96+
}
97+
return obj is RuntimeExpression runtimeExpression && Equals(runtimeExpression);
9098
}
9199

92-
/// <summary>
93-
/// Equals implementation for object of the same type.
94-
/// </summary>
95-
public bool Equals(RuntimeExpression? obj)
100+
/// <inheritdoc />
101+
public bool Equals(RuntimeExpression? other)
96102
{
97-
return obj != null && obj.Expression == Expression;
103+
return other is not null && StringComparer.Ordinal.Equals(Expression, other.Expression);
98104
}
99105

100106
/// <inheritdoc />

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ namespace Microsoft.OpenApi.Expressions
115115
public const string Prefix = "$";
116116
protected RuntimeExpression() { }
117117
public abstract string Expression { get; }
118-
public bool Equals(Microsoft.OpenApi.Expressions.RuntimeExpression? obj) { }
118+
public bool Equals(Microsoft.OpenApi.Expressions.RuntimeExpression? other) { }
119119
public override bool Equals(object? obj) { }
120120
public override int GetHashCode() { }
121121
public override string ToString() { }

0 commit comments

Comments
 (0)