Is there a way to generate multiple files through a single template / macro using Resharper?

When I write my APIs for applications, I always follow the set pattern (who doesn't work !?), which looks like this:

User (Folder/Namespace) User.cs UserDao.cs UserDaoFactory.cs UserService.cs UserServiceFactory.cs 

I know that Resharper has file templates that I already use, but it would be great if I didn’t have to add each file separately, which can become very tedious when you work with 30 subjects in the application. If you cannot do this with resharper, anyway, to make some kind of macro with Visual Studio that will execute your resharper template templates?

+6
source share
3 answers
  • Create all these classes in one file (create a file template containing a set of standard classes if you want)
  • Write your logic
  • Press Shift + Alt + L to enable focus in the file in Solution Explorer
  • Press Ctrl + Shift + R to display Refactor. This is a menu with a list of related refactoring.
  • Select Move types to mapping files , complete the refactoring wizard, and view the sections that separate individual files.
  • To put all newly created classes in a folder, select them in Solution Explorer and call Refactor this again.
  • This time select Move to folder .
  • Indicate the name of the new folder in the refactoring wizard, click "Create this folder" and complete the wizard.
+6
source

Looks like R # 8 added this feature.

On the page Help page

Starting with ReSharper 8.0, each file template can add more than one file when it is applied. This can be useful for WPF, Web and other projects where related data can be stored in different files.

Here are a few things you need to know about multi-file templates:

  • A file template always contains one primary file and, optionally, any number of secondary files. So, as soon as you add an additional file in any file template, you get a template with several files.
  • When adding a secondary file, you can link to any existing file template (Add a file from an existing template). Please note that if the link template also has several files, then only the main file of the link template will be added when applying the template.
  • A set of options covers all multifactor template files. Ie, if you use the same parameter $ PARAM $ in several files of a multi-file template, it will have the same value in all related files when the template is applied.
  • If multi-file templates have editable parameters, the Hot Spot Session, which is deployed when this template is applied, will direct you through all created files where user input is required.
+2
source

I would consider using .tt templates with ReSharper.

  • Create a master file using ReSharper.
  • using one or more tt files to automatically create dependent (.partial.cs) files with a partial keyword in it.
  • extend the generated classes if necessary.
0
source

Source: https://habr.com/ru/post/905945/


All Articles