How to get rid of Naming rule violation messages in Visual Studio?

后端 未结 9 566
我在风中等你
我在风中等你 2020-12-14 05:10

I just installed Visual Studio 2017. When I open an existing website, I get all sorts of warning messages such as this one:

IDE1006 Naming rule violat

相关标签:
9条回答
  • 2020-12-14 06:00

    You could rename the method and add the name to the attribute with the EntryPoint property.

    [System.Runtime.InteropServices.DllImport("swedll32.dll", EntryPoint = "swe_calc")]
    public static extern Int32 SweCalc(double tjd, int ipl, Int32 iflag, IntPtr xx, IntPtr serr);
    
    0 讨论(0)
  • 2020-12-14 06:02

    This can be done using normal VS2017 & VS2019 using the .editorconfig settings file, using the naming rules: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference

    The file can be created by hand, or in VS2019 you can get Visual Studio to create it for your from your preferences (i.e. after following configuring your prefs as in https://stackoverflow.com/a/41131563/131701 ), by hitting the generate editor config file from settings button.

    generate editor config file from settings button

    For example, the following sets of rules will enable camelCase for all non public methods, and keep the other default naming rules that comes with VS.

    #### Naming styles ####
    
    # Naming rules
    
    dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
    dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
    dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
    
    dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
    dotnet_naming_rule.types_should_be_pascal_case.symbols = types
    dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
    
    dotnet_naming_rule.private_method_should_be_camelcasestyle.severity = suggestion
    dotnet_naming_rule.private_method_should_be_camelcasestyle.symbols = private_method
    dotnet_naming_rule.private_method_should_be_camelcasestyle.style = camelcasestyle
    
    dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
    dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
    dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
    
    # Symbol specifications
    
    dotnet_naming_symbols.interface.applicable_kinds = interface
    dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal
    dotnet_naming_symbols.interface.required_modifiers = 
    
    dotnet_naming_symbols.private_method.applicable_kinds = method
    dotnet_naming_symbols.private_method.applicable_accessibilities = private, protected, internal, protected_internal
    dotnet_naming_symbols.private_method.required_modifiers = 
    
    dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
    dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal
    dotnet_naming_symbols.types.required_modifiers = 
    
    dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
    dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal
    dotnet_naming_symbols.non_field_members.required_modifiers = 
    
    # Naming styles
    
    dotnet_naming_style.pascal_case.required_prefix = 
    dotnet_naming_style.pascal_case.required_suffix = 
    dotnet_naming_style.pascal_case.word_separator = 
    dotnet_naming_style.pascal_case.capitalization = pascal_case
    
    dotnet_naming_style.begins_with_i.required_prefix = I
    dotnet_naming_style.begins_with_i.required_suffix = 
    dotnet_naming_style.begins_with_i.word_separator = 
    dotnet_naming_style.begins_with_i.capitalization = pascal_case
    
    dotnet_naming_style.camelcasestyle.required_prefix = 
    dotnet_naming_style.camelcasestyle.required_suffix = 
    dotnet_naming_style.camelcasestyle.word_separator = 
    dotnet_naming_style.camelcasestyle.capitalization = camel_case
    
    0 讨论(0)
  • 2020-12-14 06:03

    What this rule asserts is that fields must be private.

    You can convert it to a Property by adding the {get;set;} after the field.

    This removed the error for me.

    0 讨论(0)
提交回复
热议问题