I'm looking for a way to programatically modify the source in a solution from within Rider (or Resharper).
For example, I have an array of tuples with 1000 find/replace (F/R) strings to perform a major refactor, and I might want to find a usage of F
in an attribute, replace it with R
, then perhaps check that a 'using blah.blah;
' is present in the file's usings
section.
Obviously I can write an application to do this, but I wondered if the analyser was made visible in Rider in a way that would simplify the process and make it more generic for mass refactoring purposes.
Asked
Active
Viewed 113 times
0

JSobell
- 1,825
- 1
- 14
- 10
1 Answers
0
C# Interactive is really just a "REPL" that can execute C# code and reference assemblies (like the one from your project). It does not provide access to the source code, apart from using File I/O manually there.
Your use case does sound like a good fit for "structural search and replace" which is in ReSharper but not yet available in Rider (feel free to upvote that issue).
Another option could be to write a plugin that uses ReSharper/Rider's underlying PSI (using this template is easier to get started), or create a Roslyn-based analyzer and fix which Rider will pick up.

maartenba
- 3,344
- 18
- 31
-
I could write a plugin, but using something line LinqPad is a very quick and simple solution too. The issue with using LinqPad (or C# Interactive as-is) is that I have to reference the appropriate solution folders, and iterate the tree of source files myself, whereas Rider already has knowledge of the solution and all included (and excluded) files in the current solution. It would be great to be able to request a reference to the current active instance solution or a solution file iterator. E.g. Rider.Context.Solution.Path or Rider.Context.GetFileIterator() etc. to allow generic scripting. – JSobell Aug 30 '19 at 00:05
-
Actually, as another more common usage scenario, I wonder how many and which of my Classes have a name containing "Repository" and also implement IDisposable... Wouldn't it be awesome to be able to simply implement a 'criteria' to choose the files to be analysed and an `Action
` or even `Action – JSobell Aug 30 '19 at 00:11` as a helper to make this a common flexible utility feature :)