dav*_*v_i 18 c# resharper stylecop visual-studio visual-studio-2013
Visual Studio(或Resharper)中是否有一个设置允许您指定哪些命名空间应该是默认的以及它们放在哪个范围内?
例如,MVC项目的默认值是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Namespace
{
public class Class1
{
}
}
Run Code Online (Sandbox Code Playgroud)
但Resharper和Stylecop抱怨说:
所有using指令必须放在命名空间内.[StyleCop规则:SA1200]
代码不需要使用指令,可以安全地删除
有没有办法简单地制作默认值:
namespace Namespace
{
public class Class1
{
}
}
Run Code Online (Sandbox Code Playgroud)
小智 18
您可以在Re-sharper中进行设置.
重新锐化>选项> C#>命名空间导入>将使用指令添加到最深的范围.
一般来说,我不相信using
在你们班上排名的州议员有任何伤害.我实际上发现将它们包含在那里更容易,因此您是否要尊重该规则取决于您.
但是,如果您这样做,则所有文件模板都可用并且可以编辑.请参阅答案如何编辑新C#类/接口的Visual Studio模板?详细说明每个Visual Studio版本的位置.
一旦你在那里你可以改变布局,所以例如基本类看起来像:
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
class $safeitemrootname$
{
}
}
Run Code Online (Sandbox Code Playgroud)
您可以将此更改为以下或类似:
namespace $rootnamespace$
{
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
class $safeitemrootname$
{
}
}
Run Code Online (Sandbox Code Playgroud)
可能会有相当多的文件要改变!
现在有一种更简单的方法可以在不修改模板和 ReSharper 的情况下做到这一点。自从 Visual Studio 2019 更新 16.1 发布以来,您可以按照以下步骤在命名空间内设置 using:
归档时间: |
|
查看次数: |
10095 次 |
最近记录: |