Visual Studio: Is there a “move class to different namespace” refactoring?

前端 未结 9 1552
太阳男子
太阳男子 2020-12-20 12:17

I\'m doing some architectural cleanup that involves moving a bunch of classes into different projects and/or namespaces. Currently I\'m moving the files by hand, building, a

9条回答
  •  天命终不由人
    2020-12-20 12:37

    Visual Studio 2019 provides at least 2 built-in options:

    'Move to namespace...' refactoring can be triggered on any class, and VS will prompt for the target namespace.

    'Change namespace to...' refactoring is provided for when the current file namespace doesn't match with the folder structure.

    This can be used to move individual classes to a different namespace by:

    1. creating the desired folder structure
    2. moving the file
    3. applying the mentioned refactoring (CTRL+. with the cursor over the namespace)

    These operation ensures that all references are updated accordingly.

提交回复
热议问题