Skip to content

Commit

Permalink
Improve BalancerAttributes debugging (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Aug 7, 2023
1 parent 19e059f commit d305ee4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Grpc.Net.Client/Balancer/BalancerAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace Grpc.Net.Client.Balancer;
Expand All @@ -30,6 +31,8 @@ namespace Grpc.Net.Client.Balancer;
/// Note: Experimental API that can change or be removed without any prior notice.
/// </para>
/// </summary>
[DebuggerDisplay("{DebuggerToString(),nq}")]
[DebuggerTypeProxy(typeof(BalancerAttributesDebugView))]
public sealed class BalancerAttributes : IDictionary<string, object?>, IReadOnlyDictionary<string, object?>
{
/// <summary>
Expand Down Expand Up @@ -134,5 +137,23 @@ public bool Remove<TValue>(BalancerAttributesKey<TValue> key)
{
return _attributes.Remove(key.Key);
}

internal string DebuggerToString()
{
return $"Count = {_attributes.Count}";
}

private sealed class BalancerAttributesDebugView
{
private readonly BalancerAttributes _collection;

public BalancerAttributesDebugView(BalancerAttributes collection)
{
_collection = collection;
}

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyValuePair<string, object?>[] Items => _collection.Select(pair => new KeyValuePair<string, object?>(pair.Key, pair.Value)).ToArray();
}
}
#endif

0 comments on commit d305ee4

Please sign in to comment.