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

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.

Leave a Comment