Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?

后端 未结 8 1038
北恋
北恋 2020-12-03 16:59

Is there a way to suppress warnings in C# similar to Java\'s @SuppressWarnings annotation?

Failing that, is there another way to suppress warnings in Visual Studio?<

8条回答
  •  长情又很酷
    2020-12-03 17:16

    You can use the SuppressMessage data annotation which will prevent the warning.

    It looks something like this:

    [SuppressMessage("Reason #Enter whatever you'd like", "ID, must match what intellsense is showing it looks something like this: IDE0001", Justification = "(optional, your own description")]
    

    Here is a real world example:

    [SuppressMessage("IntelliSenseCorrection", "IDE0001", Justification = "Do Not Remove  Variable, It's Required For Dapper")]
    

提交回复
热议问题