如何阻止 ReSharper 在移动/更新命名空间声明时删除未使用的 using 语句?
当使用 ReSharper 移动/更新命名空间声明时,是否有办法阻止 ReSharper 删除未使用的 using 语句?
换句话说,如果我有一个类,例如:
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
namespace Foo.Bar
{
class MyClass
{
List<string> Names { get; set; }
}
}
并且我想使用 ReSharper 将其移动到 Foo.Bar.Utilities 命名空间中,Resharper 将删除所有未使用的使用语句并留下:
using System.Collections.Generic;
namespace Foo.Bar.Utilities
{
class MyClass
{
List<string> Names { get; set; }
}
}
但是,我不希望 ReSharper在移动名称空间声明时触摸我的Using 语句。我希望结果如下:
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
namespace Foo.Bar.Utilities
{
class MyClass
{
List<string> Names { get; set; }
}
}
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; }
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你不能明确地做到这一点。
但是,有一个选项可以指定不应删除的命名空间(Resharper 选项 -> C# -> 命名空间导入),但您需要知道您不希望它删除哪些命名空间。
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.