Equivalent functionality in VS 2022, .NET 8, and Menees.Analyzers
Opened this issue · 0 comments
I've been using C# Essentials since 2015. Since it has no official NuGet package, I've been reluctantly checking the DLL into source control to ensure it's available in every developer's environment. Recently, I got tired of doing that and decided to see what it would take to replace C# Essentials. In the Q&A section on C# Essentials - Visual Studio Marketplace, @DustinCampbell said on Nov 21, 2017:
There's not a need to support this extension for VS 2017 because most of its features are already included in VS itself. With the latest updates to VS 2017, you'll find that there are several code fixes and refactorings for transitioning your code to C# 7.
In Visual Studio 2022 and .NET 8, I found four of the five C# Essentials features built-in:
- UseNameOf (CSE0001) - .NET includes rule CA1507: Use nameof in place of string.
- UseExpressionBodiedMember (CSE0003) - VS provides the "Use expression body for method" refactoring
- ExpandExpressionBodiedMemberRefactoring - VS provides the "Use block body for method" refactoring
- ConvertToInterpolatedString - VS provides the "Convert to interpolated string" refactoring
So, the only thing missing was UseGetterOnlyAutoProperty (CSE0002). I reimplemented it in my Menees.Analyzers library in release 3.1.0. I had to rewrite it to be compliant with modern Roslyn coding practices (e.g., to avoid GetSemanticModel per rule RS1030). I took the opportunity to make it ignore properties with attributes since they're typically used with reflection and/or serialization. I also updated it to handle some new C# syntax, e.g., null-coalescing assignment, local functions, and record types. And I made the code fixer handle some whitespace formatting cases better.
I hope this helps folks looking for equivalent functionality.