locked
Method renaming RRS feed

  • Question

  • User-524495020 posted

    I've recently started to use Visual Studio and I would like to know if it's possible to rename methods (or variables) through the whole project. I´m working on web forms so I don't have all files compiled and I need to call functions in these files. Thanks

    Wednesday, May 14, 2014 11:31 AM

Answers

  • User-1454326058 posted

    Hi elhdrond,

    As far as I know, if we call the method or field in the page (E.g. .aspx), the method or field name cannot be renamed automatically if we rename the method or field name in the code file (.cs file).

    You could refer to my pervious reply to find all references, then rename them manually.

    For this feature, you could submit this feature request: http://visualstudio.uservoice.com/forums/121579-visual-studio . The Visual Studio product team is listening to user voice there. You can send your idea there so the others can vote it. If you submit this suggestion, you might post that link here which will benefit others who has the similar issue.

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 15, 2014 9:41 PM
  • User-760709272 posted

    Hello and thanks to all. Renaming with refactor or finding all references is ok to rename methods (declarations and their calls) that are compiled together, but when I try to change the name of a method in its declaration, the callings to that method in other filles of the project (like aspx) remain with the old name. I wonder if there is some kind of funtion in visual studio that can look in all files (independently if are or aren´t in the same compilation unit) and replace the names.

    Thank you

    This is one of the reasons to avoid code inside views\aspx\ascx pages as they're compiled on the fly and you only know the method no longer exists at run-time.  I'm afraid you'll have to just find and replace as already suggested.  I don't think even resharper can see your methods inside those files.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 16, 2014 3:28 AM

All replies

  • User-760709272 posted

    Give your method\variable a new name and you'll see a red line appear at the end of it.  Click it to bring down a menu that will let you make the change through the hole project.  It might not work for any instances in aspx\ascx files though.

    Wednesday, May 14, 2014 11:43 AM
  • User-1454326058 posted

    Hi elhdrond,

    What’s the result that you tried the solution that AjdyF provide? That is the good way.

    On the other hand, you could refer to these steps below to check all call reference of the method or field.

    1. Right click the method/field name
    2. Select Find ALL References

    Thanks

    Best Regards

    Thursday, May 15, 2014 1:22 AM
  • User-113911611 posted

    It is called Rename refactoring. In Visual Studio right click on a method and select Refactor - Rename.

    Thursday, May 15, 2014 1:51 AM
  • User724169276 posted

    you can use cntrl+f combination and find and replace the method names.

    Thursday, May 15, 2014 2:01 AM
  • User-524495020 posted

    Hello and thanks to all. Renaming with refactor or finding all references is ok to rename methods (declarations and their calls) that are compiled together, but when I try to change the name of a method in its declaration, the callings to that method in other filles of the project (like aspx) remain with the old name. I wonder if there is some kind of funtion in visual studio that can look in all files (independently if are or aren´t in the same compilation unit) and replace the names.

    Thank you

    Thursday, May 15, 2014 7:54 AM
  • User724169276 posted

    do cntrl + f for Entire Solution.

    Thursday, May 15, 2014 7:56 AM
  • User-1454326058 posted

    Hi elhdrond,

    As far as I know, if we call the method or field in the page (E.g. .aspx), the method or field name cannot be renamed automatically if we rename the method or field name in the code file (.cs file).

    You could refer to my pervious reply to find all references, then rename them manually.

    For this feature, you could submit this feature request: http://visualstudio.uservoice.com/forums/121579-visual-studio . The Visual Studio product team is listening to user voice there. You can send your idea there so the others can vote it. If you submit this suggestion, you might post that link here which will benefit others who has the similar issue.

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 15, 2014 9:41 PM
  • User-760709272 posted

    Hello and thanks to all. Renaming with refactor or finding all references is ok to rename methods (declarations and their calls) that are compiled together, but when I try to change the name of a method in its declaration, the callings to that method in other filles of the project (like aspx) remain with the old name. I wonder if there is some kind of funtion in visual studio that can look in all files (independently if are or aren´t in the same compilation unit) and replace the names.

    Thank you

    This is one of the reasons to avoid code inside views\aspx\ascx pages as they're compiled on the fly and you only know the method no longer exists at run-time.  I'm afraid you'll have to just find and replace as already suggested.  I don't think even resharper can see your methods inside those files.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 16, 2014 3:28 AM