Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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