我喜欢把我的 using 指令放在当前名称空间中,而不是像 VS 和 Resharper 默认放在外面那样。
是否有人知道一个宏/标准功能,排序/删除未使用的指令,并把它们 在里面的当前名称空间?
I've 编辑了我的默认视觉工作室模板 to put my using directives inside the namespace.
对于排序和删除未使用的指令,我使用 VisualStudio2008的电源命令。
更新-ReSharper 2016.1 : 此选项现在移动到 < em > 代码编辑→ C # →代码样式→添加‘ using’指令到最深的范围
你是否尝试过 ReSharper 选项:
语言→ C # →格式化样式→命名空间导入→向最深范围添加使用指令
不过,我不确定 R # 的代码清理是否会为您重新排序现有的代码。
StyleCop supports ReSharper integration starting from version 4.7.
来自 http://stylecop.codeplex.com/:
4.7与 JetBrains R # 5.1(5.1.3000.12)、 R # 6.0(6.0.2202.688)、 R # 6.1(6.1.37.86)、 R # 6.1(6.1.1000.82)和 R # 7.0兼容 (7.0.54.77) 4.7与 Visual Studio 2008、 Visual Studio 2010和 Visual Studio 11兼容 这个版本包括 StyleCop ReSharper 插件 (与 ReSharper 5.1、6.0、6.1、6.1.1及7.0)
4.7与 JetBrains R # 5.1(5.1.3000.12)、 R # 6.0(6.0.2202.688)、 R # 6.1(6.1.37.86)、 R # 6.1(6.1.1000.82)和 R # 7.0兼容 (7.0.54.77)
4.7与 Visual Studio 2008、 Visual Studio 2010和 Visual Studio 11兼容
这个版本包括 StyleCop ReSharper 插件 (与 ReSharper 5.1、6.0、6.1、6.1.1及7.0)
As of version 8.2, this has moved. It is now here:
在 VisualStudio 中 重塑者-> 选择..。
然后在选项对话框中 代码编辑-> C #-> 命名空间导入-> 必要时插入使用指令-> 将使用指令添加到最深范围
截至 Resharper 9,这已经转移到 Code Editing = > C# = > Code Style = > Reference Qualification = > Add 'using' directive to deepest scope。
Code Editing
C#
Code Style
Reference Qualification
Add 'using' directive to deepest scope
或者你可以使用新的设置搜索工具,并搜索 deepest scope。确切的设置将出现:
deepest scope
在 ReSharper 2020中,进入选项,然后:
Code Editing→ C#→ Syntax Style→ Add 'using' directive to deepest scope
Syntax Style
Resharper 2020.1更新 : 此选项现在可以在 < em > 选项→代码编辑→ C # →语法风格→参考资格和“使用”指令中找到
Image for reference