我看到了很多关于如何解决它的问题,但我想要阻止它.

要使所有字段都是CAMEL_CASE without下划线前缀(或任何匈牙利符号),我应该在.editorconfig文件中设置什么设置?

推荐答案

我自己也在研究下划线规则.似乎将CA1707设置为错误并不能解决问题,因为它只是在组件上发生故障.我可能在文件中遗漏了更多的规格,但当我试图使其工作时,我发现这gist被埋在对这issue的 comments 中.

# Start of NO underscore prefix on private fields
# Define the 'private_fields' symbol group:
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

# Define the 'notunderscored' naming style
dotnet_naming_style.notunderscored.capitalization = camel_case
dotnet_naming_style.notunderscored.required_prefix =

# Define the 'private_fields_notunderscored' naming rule
dotnet_naming_rule.private_fields_notunderscored.symbols = private_fields
dotnet_naming_rule.private_fields_notunderscored.style = notunderscored
dotnet_naming_rule.private_fields_notunderscored.severity = error
# End of No underscore prefix on private fields

要涵盖all个字段,您需要将可访问性更新为:

dotnet_naming_symbols.private_fields.applicable_accessibilities = *

如果您希望更准确地表示所有修改量的所有字段,您可能更喜欢此版本:

# Start of NO underscore prefix on all fields
# Define the 'all_fields' symbol group:
dotnet_naming_symbols.all_fields.applicable_kinds = field
dotnet_naming_symbols.all_fields.applicable_accessibilities = *

# Define the 'notunderscored' naming style
dotnet_naming_style.notunderscored.capitalization = pascal_case
dotnet_naming_style.notunderscored.required_prefix =

# Define the 'all_fields_notunderscored' naming rule
dotnet_naming_rule.all_fields_notunderscored.symbols = all_fields
dotnet_naming_rule.all_fields_notunderscored.style = notunderscored
dotnet_naming_rule.all_fields_notunderscored.severity = error
# End of No underscore prefix on all fields

以下是您将看到的错误:

  1. _someVar=不需要前缀‘_’
  2. someVar=这些单词必须以大写字符开头
  3. _SomeVar=不需要前缀‘_’
  4. SomeVar=无错误

我不能说匈牙利记数法部分;这似乎是一个困难的问题,可能需要一个定制的分析仪或使用R#或StyleCop.

Csharp相关问答推荐

将修剪声明放入LINQ中

如何从HttpContext获取请求正文

Azure Function应用(. NET 8)不将信息记录到应用洞察

HttpConext.Request.Path和HttpConext.GetEndpoint()之间的差异

try 使用C#ASP.NET收集WMI信息时访问被拒绝,但在PowerShell中工作

使用Dapper映射联接查询对象数据到使用SplitOn;

Linux Docker上的.NET6在某个时间抛出后,在加密操作期间发生System.Security.Cryptography.CryptographicException:错误

Polly重试URL复制值

BFF到具有AAD/Entra ID B2C的内部API(.NET/ASP.NET核心/标识.Web)

如何使用用于VS代码的.NET Maui扩展在我的iOS/Android设备或模拟器上进行调试?

在implementationFactory中避免循环依赖

C#动态设置ServerReport报表参数

Content WithTargetPath实际上是有效的MSBuild项吗?

为什么在使用JsonDerivedType序列化泛型时缺少$type?

具有嵌套属性的IGGroup

Xamarin.Forms中具有类似AspectFill的图像zoom 的水平滚动视图

避免在特定区域中设置Visual Studio代码的自动格式

将ValueTask发送给调用者

如何模拟一个返回OneOf IServiceA,IServiceB的方法?使用Moq

使用多个身份验证方案时引发NullReferenceException