sharpenrocks / Sharpen

Visual Studio extension that intelligently introduces new C# features into your existing codebase
https://sharpen.rocks
MIT License
418 stars 32 forks source link

Every non-abstract Command class must be sealed #10

Closed ironcev closed 5 years ago

shubh07 commented 5 years ago

Hi Igor,

Could you please provide more details or perhaps an example on the same?

Thanks, Shubham Bahuguna Quovantis

ironcev commented 5 years ago

Hi Shubham,

commands are Sharpen's Visual Studio UI Commands that can be found in the Commands folder.

Precisely, those are the classes the derive directly or indirectly from BaseSharpenCommand.

They have to be internal and sealed like e.g. AnalyzeSolutionCommand:

internal sealed class AnalyzeSolutionCommand : BaseAnalyzeCommand<AnalyzeSolutionCommand>

This coded guideline checks if a non-abstract command class (means a class that derives directly or indirectly from BaseSharpenCommand<TSharpenCommand>) is sealed. This means, in this case, the Roslyn analyzer should show error and underline the whole class definition with a red line:

internal class MySolutionCommand : BaseAnalyzeCommand<AnalyzeSolutionCommand>

In this case of course not because the class is abstract:

internal abstract class MySolutionCommand : BaseAnalyzeCommand<AnalyzeSolutionCommand>

For additional info see the implementation of all the commands in the Commands folder.

For implementing a Roslyn analyzer that checks these tutorials.

Please keep in mind that the Sharpen.CodedGuidelines project does not exist at the moment. That project has to be created as well and added to the solution before you start working on this concrete analyzer.

Please let me know if this helps and if you need any additional info.

ironcev commented 5 years ago

And yes, thanks for taking a look at the issue :-) I'm looking forward to a pull request down the road ;-)

ironcev commented 5 years ago

See #7.