Closed brian-reichle closed 3 years ago
A fun edge case:
builder.Append(foo[3..5])
is safe if foo
is a [ReadOnly]Span or [ReadOnly]Memory object as StringBuilder has appropriate overloads for that in modern .NET.
builder.Append(foo[3..5])
is not safe is foo
is a string
, as it will create a substring.
Should add a rule to warn against the following patterns when appending to a StringBuilder, as they all create easily avoidable intermediate strings:
The recommended replacements would be:
Similar warnings should be issued for other append methods.