Rocks icon indicating copy to clipboard operation
Rocks copied to clipboard

Create a Refactoring To Generate the `[Rock]` or `[RockPartial]` Declaration

Open JasonBock opened this issue 8 months ago • 1 comments

Describe the solution you'd like Right now, you have to add this attribute at the assembly level manually, like this:

[assembly: Rock(typeof(IStuff)), BuildType.Create)]

public interface IStuff
{
  void Do();
}

This isn't hard, but...what if Rocks had a refactoring that would light up for a type that could be mocked? Like, if your cursor was on the IStuff definition, you could bring up the light bulb (Ctrl + "." in Visual Studio) and select "Generate Mock Declaration" (or whatever text makes sense). The refactoring would add the [Rock(...)] declaration at the top of the current file after using statements (if they exist).

Not sure if I'd need to figure out if usings would need to be added if they don't exist, though they shouldn't be needed. The only one would be using Rocks; if it wasn't there. There's probably other devil's-in-details things that I'd have to look for.

Describe alternatives you've considered Don't add the refactoring.

JasonBock avatar Mar 27 '25 17:03 JasonBock

For reference purposes:

  • https://github.com/JasonBock/CompilerAPIBook/blob/main/Chapter%203/ExtractTypesToFiles/ExtractTypesToFiles/ExtractTypesToFilesCodeRefactoringProvider.cs
  • https://github.com/icsharpcode/RefactoringEssentials/blob/master/RefactoringEssentials/Samples/CSharp/SampleCodeRefactoringProvider.cs

JasonBock avatar Apr 13 '25 22:04 JasonBock