Disable StyleCop for specific lines

后端 未结 5 634
無奈伤痛
無奈伤痛 2021-02-05 01:12

We\'re using StyleCop in our C# projects. In some cases we\'d like to avoid the rules though. I know you can add // in the beginning of the

5条回答
  •  梦毁少年i
    2021-02-05 01:52

    You can suppress rules by adding attributes to blocks of code. Here's a simple example on a class from the blog post linked below, but you can do it on various members individually:

    [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented")]
    public class MyUndocumentedClass
    {
        public void MyUndocumentedMethod {}
    } 
    

    There's a quick overview at an MSDN blog post and a fuller description of the attributes on MSDN.

提交回复
热议问题