Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Next Next commit
KeyedCollection debug view doesn't work
  • Loading branch information
pedrobsaila committed Dec 21, 2023
commit 172fb27ca67d9cf2e3c4cabb3ad7892c3895877a
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace System.Collections.ObjectModel
{
[Serializable]
[DebuggerTypeProxy(typeof(CollectionDebugView<>))]
[DebuggerTypeProxy(typeof(KeyedCollection<,>.KeyedCollectionDebugView))]
[DebuggerDisplay("Count = {Count}")]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public abstract class KeyedCollection<TKey, TItem> : Collection<TItem> where TKey : notnull
Expand Down Expand Up @@ -280,5 +280,53 @@ private void RemoveKey(TKey key)
keyCount--;
}
}

internal sealed class KeyedCollectionDebugView
{
private readonly KeyedCollection<TKey, TItem> _collection;

public KeyedCollectionDebugView(KeyedCollection<TKey, TItem> collection)
{
ArgumentNullException.ThrowIfNull(collection);
_collection = collection;
}

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyedCollectionDebugViewItem[] Items
{
get
{
var items = new KeyedCollectionDebugViewItem[_collection.Count];
for (int i = 0; i < items.Length; i++)
{
TItem item = _collection[i];
items[i] = new KeyedCollectionDebugViewItem(_collection.GetKeyForItem(item), item);
}
return items;
}
}
}

[DebuggerDisplay("{Value}", Name = "[{Key}]")]
internal readonly struct KeyedCollectionDebugViewItem
{
public KeyedCollectionDebugViewItem(TKey key, TItem value)
{
Key = key;
Value = value;
}

public KeyedCollectionDebugViewItem(KeyValuePair<TKey, TItem> keyValue)
{
Key = keyValue.Key;
Value = keyValue.Value;
}

[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
public TKey Key { get; }

[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
public TItem Value { get; }
}
}
}