Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions src/libraries/Common/tests/System/Collections/DebugView.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ private static IEnumerable<object[]> TestDebuggerAttributes_ListInputs()
yield return new object[] { new SortedList<int, string>() };
yield return new object[] { new SortedSet<int>() };
yield return new object[] { new Stack<object>() };
#if !NETFRAMEWORK
yield return new object[] { new OrderedDictionary<string, string>() };
#endif

yield return new object[] { new Dictionary<double, float>().Keys };
yield return new object[] { new Dictionary<float, double>().Values };
Expand Down Expand Up @@ -193,6 +196,10 @@ private static IEnumerable<object[]> TestDebuggerAttributes_ListInputs()
stack.Push(2);
yield return new object[] { stack };

#if !NETFRAMEWORK
yield return new object[] { new OrderedDictionary<string, string> { { "One", "1" }, { "Two", "2" } } };
#endif

yield return new object[] { new SortedList<string, int> { { "One", 1 }, { "Two", 2 } }.Keys };
yield return new object[] { new SortedList<float, long> { { 1f, 1L }, { 2f, 2L } }.Values };

Expand Down Expand Up @@ -277,6 +284,33 @@ public static void TestDebuggerAttributes_Null(object obj)
Assert.IsType<ArgumentNullException>(tie.InnerException);
}

#if !NETFRAMEWORK
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDebuggerTypeProxyAttributeSupported))]
public static void TestDebuggerAttributes_OrderedDictionary()
{
// Validate that OrderedDictionary displays as a list of KeyValuePairs with implicit indexing
var dict = new OrderedDictionary<string, string> { { "One", "1" }, { "Two", "2" }, { "Three", "3" } };

DebuggerAttributes.ValidateDebuggerDisplayReferences(dict);
DebuggerAttributeInfo info = DebuggerAttributes.ValidateDebuggerTypeProxyProperties(dict);
PropertyInfo itemProperty = info.Properties.Single(pr => pr.GetCustomAttribute<DebuggerBrowsableAttribute>().State == DebuggerBrowsableState.RootHidden);

// The debug view should return a KeyValuePair array
var items = itemProperty.GetValue(info.Instance) as Array;
Assert.NotNull(items);
Assert.Equal(3, items.Length);

// Verify the items are KeyValuePairs in the correct order
var kvpArray = items.Cast<KeyValuePair<string, string>>().ToArray();
Assert.Equal("One", kvpArray[0].Key);
Assert.Equal("1", kvpArray[0].Value);
Assert.Equal("Two", kvpArray[1].Key);
Assert.Equal("2", kvpArray[1].Value);
Assert.Equal("Three", kvpArray[2].Key);
Assert.Equal("3", kvpArray[2].Value);
}
#endif

private class CustomKeyedCollection<TKey, TValue> : KeyedCollection<TKey, TValue> where TKey : notnull
{
public CustomKeyedCollection() : base()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Compile Include="$(CoreLibSharedDir)System\Collections\ObjectModel\CollectionHelpers.cs" Link="Common\System\Collections\ObjectModel\CollectionHelpers.cs" />
<Compile Include="System\Collections\Generic\LinkedList.cs" />
<Compile Include="System\Collections\Generic\OrderedDictionary.cs" />
<Compile Include="System\Collections\Generic\OrderedDictionaryDebugView.cs" />
<Compile Include="System\Collections\Generic\PriorityQueue.cs" />
<Compile Include="System\Collections\Generic\PriorityQueueDebugView.cs" />
<Compile Include="System\Collections\Generic\SortedDictionary.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace System.Collections.Generic
/// Operations on the collection have algorithmic complexities that are similar to that of the <see cref="List{T}"/>
/// class, except with lookups by key similar in complexity to that of <see cref="Dictionary{TKey, TValue}"/>.
/// </remarks>
[DebuggerTypeProxy(typeof(IDictionaryDebugView<,>))]
[DebuggerTypeProxy(typeof(OrderedDictionaryDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
#if SYSTEM_COLLECTIONS
public
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;

namespace System.Collections.Generic
{
internal sealed class OrderedDictionaryDebugView<TKey, TValue> where TKey : notnull
{
private readonly OrderedDictionary<TKey, TValue> _dictionary;

public OrderedDictionaryDebugView(OrderedDictionary<TKey, TValue> dictionary)
{
ArgumentNullException.ThrowIfNull(dictionary);
_dictionary = dictionary;
}

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyValuePair<TKey, TValue>[] Items
{
get
{
KeyValuePair<TKey, TValue>[] items = new KeyValuePair<TKey, TValue>[_dictionary.Count];
((ICollection<KeyValuePair<TKey, TValue>>)_dictionary).CopyTo(items, 0);
return items;
}
}
}
}
1 change: 1 addition & 0 deletions src/libraries/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
<Compile Include="$(CoreLibSharedDir)System\Collections\ObjectModel\CollectionHelpers.cs" Link="Common\System\Collections\ObjectModel\CollectionHelpers.cs" />
<Compile Include="$(CommonPath)System\Collections\Generic\EnumerableHelpers.cs" Link="Common\System\Collections\Generic\EnumerableHelpers.cs" />
<Compile Include="$(LibrariesProjectRoot)System.Collections\src\System\Collections\Generic\OrderedDictionary.cs" Link="Common\System\Collections\Generic\OrderedDictionary.cs" />
<Compile Include="$(LibrariesProjectRoot)System.Collections\src\System\Collections\Generic\OrderedDictionaryDebugView.cs" Link="Common\System\Collections\Generic\OrderedDictionaryDebugView.cs" />
<Compile Include="$(LibrariesProjectRoot)System.Collections\src\System\Collections\ThrowHelper.cs" Link="Common\System\Collections\ThrowHelper.cs" />

<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\FeatureSwitchDefinitionAttribute.cs" />
Expand Down
Loading