Skip to content

Commit b60536c

Browse files
committed
provide an implementation of CallContext.Equals/GetHashCode by deferring to CallOptions; fix #160
1 parent b931475 commit b60536c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/protobuf-net.Grpc/CallContext.Streaming.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ public readonly partial struct CallContext
1212
#pragma warning restore CA2231 // Overload operator equals on overriding value type Equals
1313
#pragma warning restore IDE0079 // Remove unnecessary suppression
1414
{
15-
/// <inheritdoc/>
16-
public override bool Equals(object? obj) => throw new NotSupportedException();
17-
/// <inheritdoc/>
18-
public override int GetHashCode() => throw new NotSupportedException();
19-
/// <inheritdoc/>
20-
public override string ToString() => nameof(CallContext);
2115

2216
/// <summary>
2317
/// Performs a full-duplex operation that will await both the producer and consumer streams

src/protobuf-net.Grpc/CallContext.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ public readonly partial struct CallContext
1919
#pragma warning restore CA2231 // Overload operator equals on overriding value type Equals
2020
#pragma warning restore IDE0079 // Remove unnecessary suppression
2121
{
22+
/// <summary>Evaluates equality between <see cref="CallContext"/> values as defined by their <see cref="CallOptions"/>.</summary>
23+
public override bool Equals(object? obj)
24+
=> obj switch
25+
{
26+
CallContext cc => this.CallOptions.Equals(cc.CallOptions),
27+
CallOptions co => this.CallOptions.Equals(co),
28+
_ => false,
29+
};
30+
31+
/// <summary>Evaluates a hashcodeas defined by the <see cref="CallOptions"/> of the instance.</summary>
32+
public override int GetHashCode() => this.CallOptions.GetHashCode();
33+
34+
/// <inheritdoc/>
35+
public override string ToString() => nameof(CallContext);
36+
2237
/// <summary>
2338
/// Default context; all default client options; no server context
2439
/// </summary>

0 commit comments

Comments
 (0)