0

I'm using Visual Studio 2017. This is not just renaming files. This is renaming classes with file name and reference. But on a mass scale.

Is there a way to rename all classes in a Namespace/folder. I want to rename all classes like myClassNameDTO to myClassNameInCache and myClassNameDTOMapper to myClassNameInCacheMapper.

I have nearly 350 of such classes.

Is there a way i can make use of VS features or C# reflection.

Jins Peter
  • 2,368
  • 1
  • 18
  • 37
  • 1
    is this duplicated? https://stackoverflow.com/questions/12347881/renaming-files-in-folder-c-sharp – Khai Nguyen Dec 10 '18 at 08:43
  • Possible duplicate of [Renaming files in folder c#](https://stackoverflow.com/questions/12347881/renaming-files-in-folder-c-sharp) – aloisdg Dec 10 '18 at 08:50
  • 2
    It is not clear if you want to rename classes (actual name after the "class" keyword), filenames or both. Could you please make it clear? – Dimitar Dec 10 '18 at 08:52
  • 1
    You don't say what version or edition of Visual Studio you are using, nor if you have any third-party tools installed, but I believe the only feature of a default Visual Studio install that can help here is the compiler (i.e. writing your own code to do this). Also, reflection works at run-time and won't help with source code. – Lance U. Matthews Dec 10 '18 at 08:54
  • I want to rename the actual classes and its references too – Jins Peter Dec 10 '18 at 08:58
  • If "DTO" appears only in class names and not e.g. in method names, variables, etc. the command "Replace in Files" will help – Klaus Gütter Dec 10 '18 at 08:59
  • @KlausGütter I cannot assume that. It is there. – Jins Peter Dec 10 '18 at 09:02
  • @Dimitar I had that in the header. – Jins Peter Dec 10 '18 at 09:02
  • 1
    I think this is one of those cases where programmers are tempted to waste more time looking for a perfect solution than it would take to just do it manually. At 10 seconds each, 350 classes is about an hour. – Robin Bennett Dec 10 '18 at 09:03
  • 2
    Possible duplicate of [Mass renaming (refactoring) in C# project](https://stackoverflow.com/questions/20972666/mass-renaming-refactoring-in-c-sharp-project) – GSerg Dec 10 '18 at 09:05
  • Actually for references you can do : Ctlr+R+R on class name and VS will do the rest. For filenames - probably it will need to be done manually. You can do the Ctrl+R+R on the type itself, but I recommend the first way. – Dimitar Dec 10 '18 at 09:05
  • 2
    @Dimitar Please read the question. I have 350+ classes to rename and all their file names and references. What i want to do is a mass ctrl+r+r – Jins Peter Dec 10 '18 at 09:12

0 Answers0