使用 ReSharper 和 Visual Studio 2010 自动重构导入/使用指令
我想自动化 Visual Studio 2010 / Resharper 5 自动插入导入指令,将我的内部命名空间放入命名空间范围中。像这样:
using System;
using System.Collections.Generic;
using System.Linq;
using StructureMap;
using MyProject.Core; // <--- Move inside.
using MyProject.Core.Common; // <--- Move inside.
namespace MyProject.DependencyResolution
{
using Core;
using Core.Common; // <--- My internal namespaces to be here!
public class DependencyRegistrar
{
...........
}
}
目前,我正在手动执行此操作,问题是每次重构时都会将 using 指令向上移动到页面的开头。
I want to automate the Visual Studio 2010 / Resharper 5 auto inserting import directives to put my internal namespaces into the namespace sphere. Like this:
using System;
using System.Collections.Generic;
using System.Linq;
using StructureMap;
using MyProject.Core; // <--- Move inside.
using MyProject.Core.Common; // <--- Move inside.
namespace MyProject.DependencyResolution
{
using Core;
using Core.Common; // <--- My internal namespaces to be here!
public class DependencyRegistrar
{
...........
}
}
Currently, I'm doing it manually, the problem is that with every refactoring the using directives going up, to the beginning of the page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 R# 5.0 中:
ReSharper->工具->清理代码。或者只需按 Ctrl+E、Ctrl+C。
然后使用打开了“优化‘使用’指令”的配置文件。
In R# 5.0:
ReSharper->Tools->Cleanup Code. Or simply press Ctrl+E, Ctrl+C.
Then use profile that has "Optimize 'using' directives" turned on.
我认为如果语句(全部)位于名称空间声明之外或(全部)位于名称空间声明内部,则可读性会更好。
在
using
语句中,最好将它们与项目语句放在最后(根据示例代码)进行排序。Resharper 遵循上述两个约定,所以我建议坚持这些约定:)
I think readability is better served if the statements are either (all) outside the namespace declaration, or (all) inside of it.
Among the
using
statements, sorting them with the project statements last (as per your example code) is then preferred.Resharper follows both the above conventions, so I would recommend sticking to those :)
没有选择可以实现这一目标。因此,最好的行动可能是您可以轻松实现的约定。
There is no option to achieve that. So probably the best action go with is a convention that you can achieve easily.