Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Sep 5, 2023
1 parent e9fd107 commit f489661
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/Grpc.Core.Api/Internal/CallDebuggerHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace Grpc.Core.Internal;
Expand Down Expand Up @@ -54,11 +55,11 @@ public static string DebuggerToString(AsyncCallState callState)
// We want to get information about a call to display during debugging, but Grpc.Core.Api does
// doesn't have access to the implementation's internal fields.
// GetDebugValue accesses values by IEnumerable + key from the implementation state.
if (callState.State is IEnumerable enumerable)
if (callState.State is IEnumerable<KeyValuePair<string, object>> enumerable)
{
foreach (DictionaryEntry entry in enumerable)
foreach (var entry in enumerable)
{
if ((string)entry.Key == key)
if (entry.Key == key)
{
return (T)entry.Value;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Grpc.Net.Client/Internal/GrpcCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,5 +1163,6 @@ private static void WriteDiagnosticEvent<
diagnosticSource.Write(name, value);
}

public IEnumerator GetEnumerator() => GrpcProtocolConstants.GetDebugEnumerator(Channel, Method, _request);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() => GrpcProtocolConstants.GetDebugEnumerator(Channel, Method, _request);
}
13 changes: 8 additions & 5 deletions src/Grpc.Net.Client/Internal/GrpcProtocolConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#endregion

using System.Collections;
using System.Collections.Generic;
using System.Net.Http.Headers;
using Grpc.Core;
using Grpc.Net.Compression;
Expand Down Expand Up @@ -88,11 +88,14 @@ internal static string GetMessageAcceptEncoding(Dictionary<string, ICompressionP
public const string ChannelKey = "Channel";
public const string RequestKey = "Request";

public static IEnumerator GetDebugEnumerator(ChannelBase channel, IMethod method, object? request)
public static IEnumerator<KeyValuePair<string, object>> GetDebugEnumerator(ChannelBase channel, IMethod method, object? request)
{
yield return new DictionaryEntry(ChannelKey, channel);
yield return new DictionaryEntry(MethodKey, method);
yield return new DictionaryEntry(RequestKey, request);
yield return new KeyValuePair<string, object>(ChannelKey, channel);
yield return new KeyValuePair<string, object>(MethodKey, method);
if (request != null)
{
yield return new KeyValuePair<string, object>(RequestKey, request);
}
}

static GrpcProtocolConstants()
Expand Down
3 changes: 1 addition & 2 deletions src/Grpc.Net.Client/Internal/IGrpcCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

#endregion

using System.Collections;
using System.Diagnostics.CodeAnalysis;
using Grpc.Core;

namespace Grpc.Net.Client.Internal;

internal interface IGrpcCall<TRequest, TResponse> : IDisposable, IEnumerable
internal interface IGrpcCall<TRequest, TResponse> : IDisposable, IEnumerable<KeyValuePair<string, object>>
where TRequest : class
where TResponse : class
{
Expand Down
3 changes: 2 additions & 1 deletion src/Grpc.Net.Client/Internal/Retry/RetryCallBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,5 +594,6 @@ public Exception CreateFailureStatusException(Status status)
throw new NotSupportedException();
}

public IEnumerator GetEnumerator() => GrpcProtocolConstants.GetDebugEnumerator(Channel, Method, _request);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() => GrpcProtocolConstants.GetDebugEnumerator(Channel, Method, _request);
}
3 changes: 2 additions & 1 deletion src/Grpc.Net.Client/Internal/Retry/StatusGrpcCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public Exception CreateFailureStatusException(Status status)
}
}

public IEnumerator GetEnumerator() => GrpcProtocolConstants.GetDebugEnumerator(_channel, _method, _request);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() => GrpcProtocolConstants.GetDebugEnumerator(_channel, _method, _request);

private sealed class StatusClientStreamWriter : IClientStreamWriter<TRequest>
{
Expand Down

0 comments on commit f489661

Please sign in to comment.