Is it possible to use ReSharper SDK to automate code editing


I am curious if it is possible to to use ReSharper SDK to do simple bulk operations like that...

1. Get all classes within particular namespace
2. Assign them particular base class
3. Create constructor with parameter which calls corresponding base constructor
4. Modify all creations of that classes to use new constructor.

Currently I have about 50 files and I don't want to do all this stuff manually :)

I think ReSharper's Search by pattern is not powerful enough to satisfy my requirements.

Any help (especially links with examples) more than welcome.

Also I would like to mention that this utility will be run only once so it would be a bit innatural to have this as a plugin :)


Comment actions Permalink

You could just use a Visual Studio macro...

Comment actions Permalink

I am not sure that Visual Studio macroses have access to code AST. From my understanding macros API will not be that helpful in my scenario

Comment actions Permalink

I don't think you need the APIs... You should be able to accomplish the same with some copy and pasting. You can very easily record temporary macros from key strokes, so:

1. Open the file and highlight the class name
2. Start recording
3. Highlight the class name
4. Copy
5. Add ": BasClass" to the end of the current line
6. Go down 1 line and press Enter
7. Type "public ", paste, type "(SomeType someType) : base(someType) { }"
8. Stop recording

Then you can open the next file, highlight the class name and play back the macro.

Tools > Macros > Record Temporary Macro

Tools > Macros > Stop Recording

Tools > Macros > Run Temporary Macro (Ctrl + Shift + P)


Please sign in to leave a comment.