Skip to content

Commit e009057

Browse files
committed
Error rework
1 parent 05ff957 commit e009057

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

src/GraphQL.Primitives/GraphQLError.cs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ public override bool Equals(object? obj) =>
4545
public bool Equals(GraphQLError? other) {
4646
if (other == null) { return false; }
4747
if (ReferenceEquals(this, other)) { return true; }
48-
if (!EqualityComparer<IDictionary<string, dynamic>?>.Default.Equals(this.Extensions, other.Extensions)) { return false; }
48+
if (!EqualityComparer<IDictionary<string, dynamic?>?>.Default.Equals(this.Extensions, other.Extensions)) { return false; }
4949
{
5050
if (this.Locations != null && other.Locations != null) {
51-
if (!Enumerable.SequenceEqual(this.Locations, other.Locations)) { return false; }
51+
if (!this.Locations.SequenceEqual(other.Locations)) { return false; }
5252
}
5353
else if (this.Locations != null && other.Locations == null) { return false; }
5454
else if (this.Locations == null && other.Locations != null) { return false; }
5555
}
5656
if (!EqualityComparer<string>.Default.Equals(this.Message, other.Message)) { return false; }
5757
{
5858
if (this.Path != null && other.Path != null) {
59-
if (!Enumerable.SequenceEqual(this.Path, other.Path)) { return false; }
59+
if (!this.Path.SequenceEqual(other.Path)) { return false; }
6060
}
6161
else if (this.Path != null && other.Path == null) { return false; }
6262
else if (this.Path == null && other.Path != null) { return false; }
@@ -68,31 +68,18 @@ public bool Equals(GraphQLError? other) {
6868
/// <inheritdoc cref="Object.GetHashCode"/>
6969
/// </summary>
7070
public override int GetHashCode() {
71-
unchecked {
72-
var hashCode = EqualityComparer<IDictionary<string, dynamic>?>.Default.GetHashCode(this.Extensions);
73-
{
74-
if (this.Locations != null) {
75-
foreach (var element in this.Locations) {
76-
hashCode = (hashCode * 397) ^ EqualityComparer<GraphQLLocation?>.Default.GetHashCode(element);
77-
}
78-
}
79-
else {
80-
hashCode = (hashCode * 397) ^ 0;
81-
}
82-
}
83-
hashCode = (hashCode * 397) ^ EqualityComparer<string>.Default.GetHashCode(this.Message);
84-
{
85-
if (this.Path != null) {
86-
foreach (var element in this.Path) {
87-
hashCode = (hashCode * 397) ^ EqualityComparer<dynamic?>.Default.GetHashCode(element);
88-
}
89-
}
90-
else {
91-
hashCode = (hashCode * 397) ^ 0;
92-
}
93-
}
94-
return hashCode;
71+
var hashCode = 0;
72+
if (this.Extensions != null) {
73+
hashCode = hashCode ^ EqualityComparer<IDictionary<string, dynamic?>>.Default.GetHashCode(this.Extensions);
74+
}
75+
if (this.Locations != null) {
76+
hashCode = hashCode ^ EqualityComparer<GraphQLLocation[]>.Default.GetHashCode(this.Locations);
77+
}
78+
hashCode = hashCode ^ EqualityComparer<string>.Default.GetHashCode(this.Message);
79+
if (this.Path != null) {
80+
hashCode = hashCode ^ EqualityComparer<dynamic>.Default.GetHashCode(this.Path);
9581
}
82+
return hashCode;
9683
}
9784

9885
/// <summary>

src/GraphQL.Primitives/GraphQLLocation.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public sealed class GraphQLLocation : IEquatable<GraphQLLocation?> {
3131
/// <param name="other">The object to compare with this instance</param>
3232
/// <returns>true if obj is an instance of <see cref="GraphQLLocation"/> and equals the value of the instance; otherwise, false</returns>
3333
public bool Equals(GraphQLLocation? other) {
34-
return other != null &&
35-
EqualityComparer<uint>.Default.Equals(this.Column, other.Column) &&
34+
if (other == null) { return false; }
35+
if (ReferenceEquals(this, other)) { return true; }
36+
return EqualityComparer<uint>.Default.Equals(this.Column, other.Column) &&
3637
EqualityComparer<uint>.Default.Equals(this.Line, other.Line);
3738
}
3839

0 commit comments

Comments
 (0)