Expand SearchValues remarks with cached-instance guidance and worked examples#12989
Conversation
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
|
@copilot Replace the Host example with a method that checks if the input is a hex string. |
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
|
@copilot Drop the "or example when escaping JSON, JavaScript, or console output" part. Let's avoid suggesting that any sample is doing sufficient validation for any specific use case. Swap the sample order such that the hex example is before the encoding one. |
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Done in e0a83b9 — dropped the "escaping JSON, JavaScript, or console output" phrasing and moved the hex validation sample ahead of the escaping one (in both the remarks and the snippet file). |
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR expands the API reference remarks for System.Buffers.SearchValues and System.Buffers.SearchValues<T> to provide clearer guidance on when to use cached SearchValues instances, which span-search APIs to prefer, and how to apply the APIs in common scenarios. It also adds a compilable snippet project with worked examples across char, byte, and string sets.
Changes:
- Expanded
SearchValues<T>andSearchValuesremarks with usage guidance, method mapping, caching recommendations, and thread-safety notes. - Added detailed remarks for
SearchValues<T>.Contains(including guidance forSearchValues<string>semantics). - Introduced a new snippet project with multiple regions demonstrating recommended patterns.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| xml/System.Buffers/SearchValues`1.xml | Adds extensive markdown remarks for SearchValues<T> and its Contains method, with multiple referenced examples. |
| xml/System.Buffers/SearchValues.xml | Updates remarks for the factory methods and adds example references for byte/char/string creation guidance. |
| snippets/csharp/System.Buffers/SearchValues/Overview/searchvalues.cs | New snippet source containing multiple regions illustrating span searching, validation, UTF-8 delimiter search, substring search, and the narrow Contains use case. |
| snippets/csharp/System.Buffers/SearchValues/Overview/Project.csproj | New snippet project to ensure examples compile in CI. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| <summary>Provides an immutable, read-only set of values optimized for efficient searching. | ||
| Instances are created by <see cref="M:System.Buffers.SearchValues.Create(System.ReadOnlySpan{System.Byte})" /> or <see cref="M:System.Buffers.SearchValues.Create(System.ReadOnlySpan{System.Char})" />.</summary> | ||
| <remarks> | ||
| <see cref="T:System.Buffers.SearchValues`1" /> instances are optimized for situations where the same set of values is frequently used for searching at run time.</remarks> | ||
| <format type="text/markdown"><