Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 19, 2025

Summary

This PR adds index information to the debugger display of OrderedDictionary<TKey, TValue> to show the position of each element in the ordered collection. The debugger display format is now [INDEX/KEY, VALUE] instead of just [KEY, VALUE].

Problem

Since .NET 9, the debugger display for dictionaries changed from [INDEX, KEY/VALUE] to [KEY, VALUE], using the generic IDictionaryDebugView. While this works well for standard dictionaries where order is not significant, OrderedDictionary maintains insertion order and supports index-based access as a key feature. Losing the index information in the debugger makes it difficult to understand the element positions and order.

Solution

Created a custom OrderedDictionaryDebugView<TKey, TValue> debug proxy that displays items with both index and key information:

Before: [10, "Ten"], [20, "Twenty"], [30, "Thirty"]
After:  [0/10, "Ten"], [1/20, "Twenty"], [2/30, "Thirty"]

The new format clearly shows:

  • Index (0, 1, 2): The position in the ordered collection
  • Key (10, 20, 30): The dictionary key for lookup
  • Value: The associated value

Changes

  1. OrderedDictionaryDebugView.cs: New custom debugger type proxy with DebugViewOrderedDictionaryItem<TKey, TValue> struct using [DebuggerDisplay("{Value}", Name = "[{Index}/{Key}]")]

  2. OrderedDictionary.cs: Updated DebuggerTypeProxy attribute from IDictionaryDebugView<,> to OrderedDictionaryDebugView<,>

  3. System.Collections.csproj: Added new file to compilation

  4. DebugView.Tests.cs: Added test cases validating the [INDEX/KEY] format for both empty and populated OrderedDictionaries

Testing

  • ✅ All 3,781 existing OrderedDictionary tests pass
  • ✅ All 108 DebugView tests pass (including new test cases)
  • ✅ CodeQL security analysis: No issues found

Fixes #issue_number

Original prompt

This section details on the original issue you should resolve

<issue_title>Add index to debugging display of OrderedDictionary<TKey, TValue></issue_title>
<issue_description>Since .NET 9 the new display info for dictionaries is [KEY, VALUE] coming from previous [INDEX, KEY/VALUE].

But index information is important here, so please add index => [INDEX/KEY, VALUE].</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #118590


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 19, 2025
@Copilot Copilot AI changed the title [WIP] Add index to debugging display of OrderedDictionary Add index to OrderedDictionary debugger display Oct 19, 2025
@Copilot Copilot AI requested a review from stephentoub October 19, 2025 20:47
Copilot finished work on behalf of stephentoub October 19, 2025 20:47
@stephentoub stephentoub added area-System.Collections and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Oct 19, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add index to debugging display of OrderedDictionary<TKey, TValue>

2 participants