EDIT: I'm using VS Code.
I'm getting the following warning for my code that prefixes private fields with an underscore:
Naming rule violation: Prefix '_' is not expected [MyProject]csharp(IDE1006)
Below is my code:
namespace MyProject
{
public class Dog
{
// Naming rule violation: Prefix '_' is not expected [MyProject]csharp(IDE1006)
private int _age;
public int Age()
{
return _age;
}
public void SetAge(int age)
{
_age = age;
}
}
}
Below is my .editorconfig file:
[*.cs]
# Require private fields to begin with an underscore (_).
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = warning
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style
dotnet_naming_symbols.instance_fields.applicable_kinds = field
dotnet_naming_style.instance_field_style.capitalization = camel_case
dotnet_naming_style.instance_field_style.required_prefix = _
I'm also posting my Directory.Build.props file just in case it's conflicting with my .editorconfig file above.
I set it to be as strict as possible so I can fix (or suppress as needed) all warnings that a stricter C# compiler would raise:
<Project>
<PropertyGroup>
<Features>strict</Features>
<WarningLevel>9999</WarningLevel>
</PropertyGroup>
</Project>
I'm looking for a solution where I can keep C#'s compiler as strict as possible and I can prefix private fields with an underscore, either by allowing them or preferably enforcing them (private fields without an underscore will get a warning).