Skip to content

IDE0071 should suggest removing ToString on {ReadOnly}Span<char> for .NET 6+ #80132

@Alex-Sob

Description

@Alex-Sob

'IDE0071: Simplify interpolation' is not suggested for Span<T> or ReadOnlySpan<T> for .NET 6+.

String interpolation was significantly improved in .NET 6+ with the introduction of interpolated string handlers. For projects targeting .NET6+ code like this should trigger IDE0071:

var span = "abc".AsSpan();
var s = $"{span.ToString()}"; // Should trigger IDE0071

In older .NET versions including .NET Framework interpolated string expressions are lowered to string.Format calls, so IDE0071 should not be reported for projects targeting older .NET versions:

var span = "abc".AsSpan();
var s = $"{span.ToString()}"; // Should not trigger IDE0071, removing ToString will cause 'ReadOnlySpan<char> cannot be converted to object'

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions