diff --git a/src/MiniValidation/AdaptiveCapacityDictionary.cs b/src/MiniValidation/AdaptiveCapacityDictionary.cs index 7777d70..71324fc 100644 --- a/src/MiniValidation/AdaptiveCapacityDictionary.cs +++ b/src/MiniValidation/AdaptiveCapacityDictionary.cs @@ -15,6 +15,8 @@ namespace MiniValidation; /// /// An type to hold a small amount of items (10 or less in the common case). /// +[DebuggerDisplay("Count = {Count}")] +[DebuggerTypeProxy(typeof(Diagnostics.CollectionDebugView))] internal sealed class AdaptiveCapacityDictionary : IDictionary, IReadOnlyDictionary where TKey : notnull { // Threshold for size of array to use. diff --git a/src/MiniValidation/Diagnostics/CollectionDebugView.cs b/src/MiniValidation/Diagnostics/CollectionDebugView.cs new file mode 100644 index 0000000..390f616 --- /dev/null +++ b/src/MiniValidation/Diagnostics/CollectionDebugView.cs @@ -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; + +/// Allows the debugger to display collections. +[ExcludeFromCodeCoverage] +internal sealed class CollectionDebugView +{ + public CollectionDebugView(IEnumerable enumeration) => _enumeration = enumeration; + + /// A reference to the enumeration to display. + private readonly IEnumerable _enumeration; + + /// The array that is shown by the debugger. + /// + /// 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. + /// + [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] + public object[] Items => _enumeration.Cast().ToArray(); +} +#endif