Visual Studio(或 ReSharper)中是否有一个设置允许您指定哪些命名空间应该是默认的以及它们放在哪个范围内?
例如 MVC 项目的默认值是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Namespace
{
public class Class1
{
}
}
但 ReSharper 和 StyleCop 提示:
All using directives must be placed inside of the namespace. [StyleCop Rule: SA1200]
Using directive is not required by the code and can be safely removed
有没有办法简单地设置默认值:
namespace Namespace
{
public class Class1
{
}
}
最佳答案
您可以在 Re-sharper 中设置它。
Re-sharper > 选项 > C# > 命名空间导入 > 将 using 指令添加到最深的范围。
更新:从 VS2015 和 Resharper10 开始,这已经发生变化。它现在位于:
代码编辑 > C# > 代码风格 > 引用限定 > 将“using”指令添加到最深的范围
关于c# - 阻止 Visual Studio 将 using 指令放在命名空间之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26629264/