You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The rule should flag instances of a pattern like str1 + str2.Substring(...) + str3 or string.Concat(str1, str2.Substring(...), str3) and instead switch to using the span-based string.Concat(str1, str2.AsSpan(...), str3).
Find calls to str1 + str2.Substring(...) + ... (but not string.Concat(str1, str2.Substring(...), ...), since that's in a different analyzer)
If there's an applicable overload of string.Concat that accepts ReadOnlySpan<char> with the correct number of arguments, suggest changing the Substring call to AsSpan and calling string.Concat
Don't arbitrarily suggest changing str1 + str2 to string.Concat(str1, str2).
@Mrnikbobjeff was this one of the analyzer proposals that you had already started working on? It's been approved, so let us know if you'd like to work on it.
Quick question about trivia: if we have foo /*A*/ + /*B*/ bar.Substring(1), do we want to turn it into string.Concat(foo, /*A*/ /*B*/ bar.AsSpan(1))
or string.Concat(foo /*A*/ , /*B*/ bar.AsSpan(1))?
If we want the first option, do we want to collapse the double spaces between /*A*/ and /*B*/?
If we want the second option, do we want to collapse the extra spaces to the left of the comma?
Activity
[-]Use string.Concat[/-][+]Use span-based string.Concat[/+]jeffhandley commentedon Mar 21, 2020
Estimates:
Mrnikbobjeff commentedon Sep 3, 2020
The invocation of concat with substring can be caught by the string.Substring(x) analyzer which is already proposed
buyaa-n commentedon Nov 6, 2020
Should this analyzer flag a case without Substring() and suggest Concat? like
str1 + str2 + str3 => string.Concat(str1, str2, str3)bartonjs commentedon Nov 10, 2020
Video
str1 + str2.Substring(...) + ...(but notstring.Concat(str1, str2.Substring(...), ...), since that's in a different analyzer)Category: Performance
Suggested severity: Info
carlossanlop commentedon Nov 10, 2020
@Mrnikbobjeff was this one of the analyzer proposals that you had already started working on? It's been approved, so let us know if you'd like to work on it.
NewellClark commentedon Jan 25, 2021
I would like to be assigned to this.
NewellClark commentedon Jan 29, 2021
Quick question about trivia: if we have
foo /*A*/ + /*B*/ bar.Substring(1), do we want to turn it intostring.Concat(foo, /*A*/ /*B*/ bar.AsSpan(1))or
string.Concat(foo /*A*/ , /*B*/ bar.AsSpan(1))?If we want the first option, do we want to collapse the double spaces between
/*A*/and/*B*/?If we want the second option, do we want to collapse the extra spaces to the left of the comma?
NewellClark commentedon May 22, 2021
Analyzer/fixer and docs have been completed. This issue can be closed.
jeffhandley commentedon May 22, 2021
Thanks, @NewellClark!!