Visual Studio: GlobalSuppressions.cs: 前缀 ~P: 用于 SuppressMessage 中的属性目标
Visual Studio: GlobalSuppressions.cs: Prefix ~P: for attribute Target in SuppressMessage
我在 Visual Studio 2017 年抑制了几条 (IntelliSense) 消息。我在文件 GlobalSuppressions.cs
中创建了条目,例如:
[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")]
属性 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."
中的前缀 ~M:
和 ~P:
我终于找到了 documentation I was looking for。上面写着:
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.
我想第一个和最后一个条目与抑制消息无关,前导 ~
按照约定固定。
因此,例如,要在整个命名空间中抑制给定类型的所有警告,您可以编写:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.", Scope = "namespaceanddescendants", Target = "~P:MyProg.Class2.Setter1")]
顺便说一句,Scope
的允许值描述为 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.
我在 Visual Studio 2017 年抑制了几条 (IntelliSense) 消息。我在文件 GlobalSuppressions.cs
中创建了条目,例如:
[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")]
属性 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."
~M:
和 ~P:
我终于找到了 documentation I was looking for。上面写着:
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. |
我想第一个和最后一个条目与抑制消息无关,前导 ~
按照约定固定。
因此,例如,要在整个命名空间中抑制给定类型的所有警告,您可以编写:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.", Scope = "namespaceanddescendants", Target = "~P:MyProg.Class2.Setter1")]
顺便说一句,Scope
的允许值描述为 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. |