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

后端 未结 9 565
我在风中等你
我在风中等你 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 05:38

    If you hover over the naming rule violation, you can use Alt + Enter to bring up the naming styles for that language. You can also use Tools -> Options -> Text Editor -> {language} -> Code Style -> Naming.

    For camelCase rules on Methods, you can add a new rule and set that to Camel Case. When you close the code file and open it up again, you shouldn't see that warning anymore. Not sure why this isn't a default option, but it wasn't in my case (using Visual Code 15.8). I had to edit styles to match our company standards.

    Sample C# Naming Styles Settings

    0 讨论(0)
  • 2020-12-14 05:42

    If you want to omit or void the warning message in a method, you can use the SuppressMessage from the namespace System.Diagnostics.CodeAnalysis:

    [SuppressMessage("Microsoft.Design", "IDE1006", Justification = "Rule violation aceppted due blah blah..")]
    

    The Justification property is optional, but it's worth spending a moment writing a reason, to let your team know that the code is revised and is ok.

    0 讨论(0)
  • 2020-12-14 05:46

    If you want to suppress it only in some files or areas you can use the following:

    #pragma warning disable IDE1006
    
    // the code with the warning
    
    #pragma warning restore IDE1006
    
    0 讨论(0)
  • 2020-12-14 05:57

    If you need to get rid of these messages you could also just suppress them.

    0 讨论(0)
  • 2020-12-14 05:59

    disable the rule. rightclick error message and select severity to none

    0 讨论(0)
  • 2020-12-14 06:00

    Its a new configurable feature, if you go to

    Options → Text Editor → Your language (I did C#) → Code Style → Naming

    In there I went to Manage Styles add camel Case (its in there but you need to add it to your selectable): go to the "+" sign, then add your rule accordingly.

    Important: Close your solution and re-open it for changes to take effect.

    For example, I only use camel Case for private methods. So I choose Private Method and required Style the new one I created "camel Case" and set it to Severity Suggestion (I also promoted it to the top).

    The built in are all "Suggestions" too so you can also just turn off Messages.

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