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
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ namespace System.Buffers
/// <remarks>
/// <see cref="SearchValues{T}"/> are optimized for situations where the same set of values is frequently used for searching at runtime.
/// </remarks>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
[DebuggerTypeProxy(typeof(SearchValuesDebugView<>))]
public class SearchValues<T> where T : IEquatable<T>?
{
// Only CoreLib can create derived types
private protected SearchValues() { }

/// <summary>Used by <see cref="SearchValuesDebugView{T}"/>.</summary>
/// <summary>Used by <see cref="DebuggerDisplay"/>s and <see cref="DebuggerTypeProxyAttribute"/>s for <see cref="SearchValues{T}"/>.</summary>
internal virtual T[] GetValues() => throw new UnreachableException();

/// <summary>
Expand Down Expand Up @@ -80,5 +81,24 @@ internal static int LastIndexOfAnyExcept(ReadOnlySpan<T> span, SearchValues<T> v

return values.LastIndexOfAnyExcept(span);
}

private string DebuggerDisplay
{
get
{
T[] values = GetValues();

string display = $"{GetType().Name}, Count={values.Length}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using this in my testing, helps a ton when there are multiple generic variants.

Type implType = searchValuesInstance.GetType();
string impl = $"{implType.Name} [{string.Join(", ", implType.GenericTypeArguments.Select(t => t.Name))}]";

E.g.
SingleStringSearchValuesThreeChars`2 [ValueLength8OrLonger, CaseSensitive]

if (values.Length > 0)
{
display += ", Values=";
display += typeof(T) == typeof(char) ?
"\"" + new string(Unsafe.As<T[], char[]>(ref values)) + "\"" :
string.Join(",", values);
}

return display;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.Buffers
{
internal sealed class SearchValuesDebugView<T> where T : IEquatable<T>?
Expand All @@ -13,6 +15,7 @@ public SearchValuesDebugView(SearchValues<T> values)
_values = values;
}

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public T[] Values => _values.GetValues();
}
}