我正试图在 Visual Studio 2022 的 .editorconfig
文件中设置 C#
的样式规则,以便始终生成符合我项目中使用的代码风格。
目前,VS 生成属性或字段时使用的是 String
和 Int32
,而不是 string
和 int
。虽然我知道 string
是 String
的别名,但我想在定义类型时使用 string
和 int
。
然而,当尝试访问静态方法(例如 String.IsNullOrEmpty(String))时,我想使用 String
而不是 string
。因此,应该采用以下样式:
public class Test
{
// use lowercase here (string not String)
private string _name;
// use lowercase here (string not String)
public string Title { get; set; }
public Test(string name)
{
// use uppercase here (String.IsNullOrEmpty(name) not string.IsNullOrEmpty(name))
if (String.IsNullOrEmpty(name))
{
throw new Exception("...");
}
_name = name;
}
}
我该在
.editorconfig
文件中添加哪些规则,以便让Visual Studio 2022遵循上述样式?