dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.01k stars 4.03k forks source link

Option to prefer `new()` over `var` in assignments. #61557

Open las-nsc opened 2 years ago

las-nsc commented 2 years ago

Brief description:

Since using type inferrence for constructors has been possible using new(), it's more concise to use: Thing thing = new(); than var thing = new Thing(); It would be nice if this could be applied as a suggestion.

Languages applicable:

I think only C#. I don't use other .Net languages, but it should apply to all it can I guess.

Code example that the analyzer should report:

Explained above.

Additional information:

Is any needed?

Documentation requirements:

When this analyzer is implemented, it must be documented by following the steps at Documentation for IDE CodeStyle analyzers.

las-nsc commented 2 years ago

If https://github.com/dotnet/csharplang/discussions/6175 were implemented, the same should apply for that.