roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

`[RCS1264]` `roslynator_use_var = when_type_is_obvious` should recognize `StringBuilder`

Open RenderMichael opened this issue 1 year ago • 0 comments
trafficstars

Product and Version Used:

NuGet package v. 4.10.0

Steps to Reproduce:

in .editorconfig:

roslynator_use_var = when_type_is_obvious

Code:

internal class Demo
{
    public static string StringBuilderDemo(List<int> entries)
    {
        var sb = new StringBuilder("Entries: ")
            .Append(entries.Count)
            .Append('.');

        return sb.ToString();
    }
}

Actual Behavior:

On the var keyword: RCS1264: Use 'var' or explicit type

Expected Behavior:

The StringBuilder is a well-known type, and this is not an uncommon pattern in my experience.

Much like Parse(string) methods, StringBuilder's Append methods should be recognized as "obviously" returning StringBuilder.

RenderMichael avatar Apr 04 '24 14:04 RenderMichael