I suppressed several (IntelliSense) messages in Visual Studio 2017. I created entries in file GlobalSuppressions.cs
like:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Wrong Usage", "DisposableFixer:Undisposed ressource.", Justification = "<Pending>", Scope = "member", Target = "~M:MyProg.Class1.....Method1")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.", Justification = "<Pending>", Scope = "member", Target = "~P:MyProg.Class2.Setter1")]
The prefixes ~M:
and ~P:
in attribute Target
seem to be some kind of filter. What do they mean? The only document I find about Target
, is: "It must contain a fully-qualified item name."
I finally found the documentation I was looking for. It reads:
The first part of the string identifies the kind of member being documented, via a single character followed by a colon. The following kinds of members are defined:
Character | Description |
---|---|
E | Event |
M | Method (including constructors, destructors, and operators) |
N | Namespace |
P | Property (including indexers) |
T | Type (such as class, delegate, enum, interface, and struct) |
! | Error string; the rest of the string provides information about the error. For example, the documentation generator generates error information for links that cannot be resolved. |
I guess the first and the last entries are not relevant for suppression messages and the leading ~
is fixed by convention.
So, for example, to suppress all warnings of a given type in a whole namespace, you write:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.", Scope = "namespaceanddescendants", Target = "~P:MyProg.Class2.Setter1")]
BTW, the allowed values for Scope
are described here:
Value | Description |
---|---|
"member" | Suppresses warnings against a member. |
"module" | Suppresses warnings against an assembly. It is a global suppression that applies to the entire project. |
"namespace" | This scope suppresses warnings against the namespace itself. It does not suppress warnings against types within the namespace. |
"namespaceanddescendants" | Suppresses warnings in a namespace and all its descendant symbols. This value is ignored by legacy code analysis. |
"type" | Suppresses warnings against a type. |
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With