Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop ReSharper from removing unused Using statements when moving/updating Namespace declarations?

When using ReSharper to move/update namespace declarations, is there a way to stop ReSharper from removing unused Using statements?

In other words, if I have a class such as:

using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace Foo.Bar
{
    class MyClass
    {
        List<string> Names { get; set; }
    }
}

And I want to move it into the Foo.Bar.Utilities namespace using ReSharper, Resharper will remove all the unused Using statements and leave me with:

using System.Collections.Generic;

namespace Foo.Bar.Utilities
{
    class MyClass
    {
        List<string> Names { get; set; }
    }
}

However, I do not want ReSharper to touch my Using statements while moving the namespace declaration. I'd prefer to have the result as:

using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace Foo.Bar.Utilities
{
    class MyClass
    {
        List<string> Names { get; set; }
    }
}
like image 380
Metro Smurf Avatar asked Jan 24 '11 16:01

Metro Smurf


1 Answers

I don't think you can do this unequivocally.

However, there is an option to specify namespaces that should not be removed (Resharper Options -> C# -> Namespace Imports), but you need to know which ones you don't want it to remove.

like image 125
Joe Avatar answered Sep 20 '22 13:09

Joe