From d305ee4bc6c48d6b66ac360fa07abbc58e08651e Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 7 Aug 2023 21:08:50 +0800 Subject: [PATCH] Improve BalancerAttributes debugging (#2235) --- .../Balancer/BalancerAttributes.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Grpc.Net.Client/Balancer/BalancerAttributes.cs b/src/Grpc.Net.Client/Balancer/BalancerAttributes.cs index 7f4d42a82..4d7069b19 100644 --- a/src/Grpc.Net.Client/Balancer/BalancerAttributes.cs +++ b/src/Grpc.Net.Client/Balancer/BalancerAttributes.cs @@ -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; @@ -30,6 +31,8 @@ namespace Grpc.Net.Client.Balancer; /// Note: Experimental API that can change or be removed without any prior notice. /// /// +[DebuggerDisplay("{DebuggerToString(),nq}")] +[DebuggerTypeProxy(typeof(BalancerAttributesDebugView))] public sealed class BalancerAttributes : IDictionary, IReadOnlyDictionary { /// @@ -134,5 +137,23 @@ public bool Remove(BalancerAttributesKey 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[] Items => _collection.Select(pair => new KeyValuePair(pair.Key, pair.Value)).ToArray(); + } } #endif