Conversation
…edApiVersionDescriptionProvider and remove it
… Where applicable, update extension methods to extension properties.
…ed and emit policy links in the x-api-versioning extension.
… build-time OpenAPI document generation
src/AspNet/WebApi/src/Asp.Versioning.WebApi/Dispatcher/HttpResponseExceptionFactory.cs
Fixed
Show fixed
Hide fixed
src/AspNetCore/WebApi/src/Asp.Versioning.Mvc.ApiExplorer/VersionedApiDescriptionProvider.cs
Fixed
Show fixed
Hide fixed
src/AspNetCore/WebApi/src/Asp.Versioning.OpenApi/Transformers/XmlComments.cs
Fixed
Show fixed
Hide fixed
| else | ||
| { | ||
| markdown.Append( "- [" ) | ||
| .Append( link.Title.ToString() ) |
Check notice
Code scanning / CodeQL
Redundant ToString() call Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
In general, to fix redundant ToString() calls in string concatenation or StringBuilder usage, you can either (a) pass the original object to APIs that already call ToString() internally, or (b) ensure you pass a string directly when the source is already a string. Here, link.Title is a StringSegment, and StringSegment has an implicit conversion to string. The best fix is to remove the explicit .ToString() and rely on that implicit conversion, which keeps behavior the same but avoids an unnecessary explicit call and satisfies the analyzer.
Concretely, in src/AspNetCore/WebApi/src/Asp.Versioning.OpenApi/Transformers/ApiExplorerTransformer.cs, within the RenderLink method, change line 245 from .Append( link.Title.ToString() ) to .Append( (string) link.Title ). This makes it explicit that a string is being appended while avoiding the redundant ToString() call. No new methods or imports are needed; we only adjust that single call site.
| @@ -242,7 +242,7 @@ | ||
| else | ||
| { | ||
| markdown.Append( "- [" ) | ||
| .Append( link.Title.ToString() ) | ||
| .Append( (string) link.Title ) | ||
| .Append( "](" ) | ||
| .Append( link.LinkTarget.OriginalString ) | ||
| .Append( ')' ); |
.NET 10 Preview 1
Contains the baseline set of changes for the .NET 10 - Preview 1 release.