How to suppress a StyleCop warning?

后端 未结 12 1397
心在旅途
心在旅途 2020-11-27 18:23

I\'m using StyleCop and want to suppress some warning which does not suit my style. I prefer to have solution for

1) in-line code suppressing
2) global setting

12条回答
  •  天命终不由人
    2020-11-27 18:55

    The README.md for the StyleCop.Analyzers NuGet package used by Visual Studio 2015+ contains a link to the documentation for the rules. The documentation for each rule contains a "How to suppress violations" section. For the SA1202 rule, the options are:

    [SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "Reviewed.")]
    

    and

    #pragma warning disable SA1202 // ElementsMustBeOrderedByAccess
    #pragma warning restore SA1202 // ElementsMustBeOrderedByAccess
    

提交回复
热议问题