How to refactor namespaces in C# without affecting other projects?

Viewed 122

I have a Nuget package where I started out by keeping most of my classes and interfaces in the base namespace. Over time the default namespace has become cluttered with a lot of classes that are independent from each other and I would like to move them to their own namespaces. As an example I would like to convert the below without affecting existing users of the projects:

 namespace WebTestSuite
 {
     /// <summary>
     /// Public test result properties
     /// </summary>
     public interface ITestResult
     {
           /* Interface definition here */
     }
 }

To:

 namespace WebTestSuite.Results
 {
     /// <summary>
     /// Public test result properties
     /// </summary>
     public interface ITestResult
     {
           /* Interface definition here */
     }
 }

The end goal is to allow me to refactor namespaces in my project, and when users get the latest version of the package, their references to WebTestSuite.ITestResult will automatically be updated to WebTestSuite.Results.ITestResult.

I was thinking I could write a migration script, but wasn't sure if that was necessary or if there are any frameworks or anything that would make this easier. Any suggestions would be greatly appreciated.

1 Answers

You can try Resharper. It will provide lots of control over code refactoring with minimal effort. With resharper you can follow this guideline.

Related