Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/MiniValidation/AdaptiveCapacityDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace MiniValidation;
/// <summary>
/// An <see cref="IDictionary{TKey, TValue}"/> type to hold a small amount of items (10 or less in the common case).
/// </summary>
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(Diagnostics.CollectionDebugView))]
internal sealed class AdaptiveCapacityDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IReadOnlyDictionary<TKey, TValue> where TKey : notnull
{
// Threshold for size of array to use.
Expand Down
29 changes: 29 additions & 0 deletions src/MiniValidation/Diagnostics/CollectionDebugView.cs
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.

#if NET6_0_OR_GREATER
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace MiniValidation.Diagnostics;

/// <summary>Allows the debugger to display collections.</summary>
[ExcludeFromCodeCoverage]
internal sealed class CollectionDebugView
{
public CollectionDebugView(IEnumerable enumeration) => _enumeration = enumeration;

/// <summary>A reference to the enumeration to display.</summary>
private readonly IEnumerable _enumeration;

/// <summary>The array that is shown by the debugger.</summary>
/// <remarks>
/// Every time the enumeration is shown in the debugger, a new array is created.
/// By doing this, it is always in sync with the current state of the enumeration.
/// </remarks>
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public object[] Items => _enumeration.Cast<object>().ToArray();
}
#endif