Skip to content

Commit d19373f

Browse files
authored
Update SuppressMessageAttribute (dotnet#5293)
1 parent 2cf95f2 commit d19373f

File tree

1 file changed

+82
-69
lines changed

1 file changed

+82
-69
lines changed

xml/System.Diagnostics.CodeAnalysis/SuppressMessageAttribute.xml

Lines changed: 82 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,24 @@
4848
</Attribute>
4949
</Attributes>
5050
<Docs>
51-
<summary>Suppresses reporting of a specific static analysis tool rule violation, allowing multiple suppressions on a single code artifact. Does not apply to compiler diagnostics.</summary>
51+
<summary>Suppresses reporting of a specific code analysis rule violation, allowing multiple suppressions on a single code artifact. Does not apply to compiler diagnostics.</summary>
5252
<remarks>
53-
<format type="text/markdown"><![CDATA[
54-
55-
## Remarks
56-
This attribute can be applied to any application element. For a complete list of the violations that can be suppressed, see [Code Analysis for Managed Code Warnings](/visualstudio/code-quality/code-analysis-for-managed-code-warnings).
57-
53+
<format type="text/markdown"><![CDATA[
54+
55+
## Remarks
56+
This attribute can be applied to any application element. For a complete list of the violations that can be suppressed, see [Code quality rules](/dotnet/fundamentals/code-analysis/quality-rules/).
57+
5858
> [!NOTE]
59-
> The <xref:System.Diagnostics.ConditionalAttribute> is applied to this class, specifying the preprocessing symbol "CODE_ANALYSIS" as the conditional symbol that determines whether the attribute call is included or omitted. If the symbol is defined, the attribute call is included; otherwise, the call is omitted.
60-
>
61-
> When you right-click a Code Analysis warning in the Visual Studio **Error List** and then click **Suppress Message(s)**, a **SuppressMessage** attribute is added either in your code or to the project's global suppressions file. For more information about the **SuppressMessage** attribute and its use in Visual Studio, see [In Source Suppression Overview](/visualstudio/code-quality/in-source-suppression-overview).
59+
> The <xref:System.Diagnostics.ConditionalAttribute> is applied to this class, specifying the preprocessing symbol "CODE_ANALYSIS" as the conditional symbol that determines whether the attribute call is included or omitted. If the symbol is defined, the attribute call is included; otherwise, the call is omitted.
60+
>
61+
> When you right-click a code analysis warning in Visual Studio and choose **Suppress <rule-ID> > in Suppression File** or **Suppress <rule-ID> > in Source (attribute)**, a **SuppressMessage** attribute is added to either the global suppressions file or to the source code file. For more information about the **SuppressMessage** attribute and its use in Visual Studio, see [Suppress code analysis violations](/visualstudio/code-quality/in-source-suppression-overview).
62+
63+
## Examples
64+
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress performance warning messages.
6265
63-
## Examples
64-
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress performance warning messages.
65-
6666
[!code-csharp[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/CS/program.cs#1)]
67-
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#1)]
68-
67+
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#1)]
68+
6969
]]></format>
7070
</remarks>
7171
</Docs>
@@ -107,24 +107,24 @@
107107
<Docs>
108108
<param name="category">The category for the attribute.</param>
109109
<param name="checkId">The identifier of the analysis tool rule the attribute applies to.</param>
110-
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute" /> class, specifying the category of the static analysis tool and the identifier for an analysis rule.</summary>
110+
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute" /> class, specifying the category of the code analysis tool and the identifier for an analysis rule.</summary>
111111
<remarks>
112-
<format type="text/markdown"><![CDATA[
113-
114-
## Remarks
112+
<format type="text/markdown"><![CDATA[
113+
114+
## Remarks
115+
116+
The `category` parameter value is specific to the analysis tool and categorizes the rule identified by the `checkId` parameter. The two parameters concatenated together form a unique identifier for the rule.
115117
116-
The `category` parameter value is specific to the analysis tool and categorizes the rule identified by the `checkId` parameter. The two parameters concatenated together form a unique identifier for the rule.
117-
118118
> [!NOTE]
119119
> The preprocessor symbol "CODE_ANALYSIS" must be defined for this attribute to be effective. The absence of the preprocessor symbol results in the attribute not being applied.
120-
121-
## Examples
122120
123-
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress warnings for the `Microsoft.Performance` category and the `CA1801` and `CA1804` check identifiers. This code example is part of a larger example provided for the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> class.
124-
121+
## Examples
122+
123+
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress warnings for the `Microsoft.Performance` category and the `CA1801` and `CA1804` check identifiers. This code example is part of a larger example provided for the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> class.
124+
125125
[!code-csharp[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/CS/program.cs#2)]
126-
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#2)]
127-
126+
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#2)]
127+
128128
]]></format>
129129
</remarks>
130130
</Docs>
@@ -167,18 +167,18 @@ The following code example shows the use of the <xref:System.Diagnostics.CodeAna
167167
<summary>Gets the category identifying the classification of the attribute.</summary>
168168
<value>The category identifying the attribute.</value>
169169
<remarks>
170-
<format type="text/markdown"><![CDATA[
171-
172-
## Remarks
170+
<format type="text/markdown"><![CDATA[
171+
172+
## Remarks
173173
174174
The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.Category%2A> property describes the tool or tool analysis category for which a message suppression attribute applies.
175-
176-
## Examples
177-
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress warnings for the `Microsoft.Performance` category and the `CA1801` and `CA1804` check identifiers. This code example is part of a larger example provided for the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> class.
178-
175+
176+
## Examples
177+
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress warnings for the `Microsoft.Performance` category and the `CA1801` and `CA1804` check identifiers. This code example is part of a larger example provided for the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> class.
178+
179179
[!code-csharp[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/CS/program.cs#2)]
180-
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#2)]
181-
180+
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#2)]
181+
182182
]]></format>
183183
</remarks>
184184
</Docs>
@@ -218,21 +218,21 @@ The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.Category%2A>
218218
<ReturnType>System.String</ReturnType>
219219
</ReturnValue>
220220
<Docs>
221-
<summary>Gets the identifier of the static analysis tool rule to be suppressed.</summary>
222-
<value>The identifier of the static analysis tool rule to be suppressed.</value>
221+
<summary>Gets the identifier of the code analysis tool rule to be suppressed.</summary>
222+
<value>The identifier of the code analysis tool rule to be suppressed.</value>
223223
<remarks>
224-
<format type="text/markdown"><![CDATA[
225-
226-
## Remarks
224+
<format type="text/markdown"><![CDATA[
225+
226+
## Remarks
227227
228228
Concatenated together, the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.Category%2A> and <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.CheckId%2A> properties form a unique check identifier.
229-
230-
## Examples
231-
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress warnings for the `Microsoft.Performance` category and the `CA1801` and `CA1804` check identifiers. This code example is part of a larger example provided for the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> class.
232-
229+
230+
## Examples
231+
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress warnings for the `Microsoft.Performance` category and the `CA1801` and `CA1804` check identifiers. This code example is part of a larger example provided for the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> class.
232+
233233
[!code-csharp[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/CS/program.cs#2)]
234-
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#2)]
235-
234+
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#2)]
235+
236236
]]></format>
237237
</remarks>
238238
</Docs>
@@ -310,21 +310,24 @@ Concatenated together, the <xref:System.Diagnostics.CodeAnalysis.SuppressMessage
310310
<ReturnType>System.String</ReturnType>
311311
</ReturnValue>
312312
<Docs>
313-
<summary>Gets or sets an optional argument expanding on exclusion criteria.</summary>
313+
<summary>Gets or sets the expanded exclusion criteria.</summary>
314314
<value>A string containing the expanded exclusion criteria.</value>
315315
<remarks>
316-
<format type="text/markdown"><![CDATA[
317-
318-
## Remarks
319-
320-
The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.MessageId%2A> property is an optional argument that specifies additional exclusion where the literal metadata target is not sufficiently precise. For example, the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> cannot be applied within a method, and it may be desirable to suppress a violation against a statement in the method that will give a rule violation, but not against all statements in the method.
321-
322-
## Examples
323-
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress warnings for a specific parameter in a method declaration and a specific field in the method. This code example is part of a larger example provided for the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> class.
324-
316+
<format type="text/markdown"><![CDATA[
317+
318+
## Remarks
319+
320+
The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.MessageId%2A> property is an optional argument that specifies additional exclusion where the literal metadata target is not sufficiently precise. For example, the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> cannot be applied within a method, but you may want to suppress a violation against a single statement in the method.
321+
322+
> [!NOTE]
323+
> This property is only respected by [legacy code analysis](/visualstudio/code-quality/static-code-analysis-for-managed-code-overview).
324+
325+
## Examples
326+
The following code example shows the use of the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute to suppress warnings for a specific parameter in a method declaration and a specific field in the method. This code example is part of a larger example provided for the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> class.
327+
325328
[!code-csharp[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/CS/program.cs#2)]
326-
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#2)]
327-
329+
[!code-vb[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.CodeAnalysis.SuppressMessageAttribute/VB/program.vb#2)]
330+
328331
]]></format>
329332
</remarks>
330333
</Docs>
@@ -366,12 +369,22 @@ The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.MessageId%2A>
366369
<summary>Gets or sets the scope of the code that is relevant for the attribute.</summary>
367370
<value>The scope of the code that is relevant for the attribute.</value>
368371
<remarks>
369-
<format type="text/markdown"><![CDATA[
370-
372+
<format type="text/markdown"><![CDATA[
373+
371374
## Remarks
372375
373-
The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.Scope%2A> property is an optional argument that specifies the metadata scope for which the attribute is relevant. Possible values for managed metadata include "member", "resource", "module", "type", "method", "namespace", or "namespaceanddescendants" (available since Visual Studio 2019). For more information about scopes, see [Suppress code analysis warnings](/visualstudio/code-quality/in-source-suppression-overview#suppressmessage-attribute).
374-
376+
The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.Scope%2A> property is an optional argument that specifies the metadata scope for which the attribute is relevant. The following table shows the possible values.
377+
378+
| Value | Description |
379+
| - | - |
380+
| `"member"` | Suppresses warnings against a member. |
381+
| `"module"` | Suppresses warnings against an assembly. It is a global suppression that applies to the entire project. |
382+
| `"namespace"` | This scope suppresses warnings against the namespace itself. It does not suppress warnings against types within the namespace. |
383+
| `"namespaceanddescendants"` | Suppresses warnings in a namespace and all its descendant symbols. This value is ignored by [legacy code analysis](/visualstudio/code-quality/static-code-analysis-for-managed-code-overview). |
384+
| `"type"` | Suppresses warnings against a type. |
385+
386+
For [legacy code analysis](/visualstudio/code-quality/static-code-analysis-for-managed-code-overview), `"resource"` is also a valid value. For more information about scopes, see [Suppress code analysis warnings](/visualstudio/code-quality/in-source-suppression-overview#suppressmessage-attribute).
387+
375388
]]></format>
376389
</remarks>
377390
</Docs>
@@ -410,14 +423,14 @@ The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.Scope%2A> pro
410423
<ReturnType>System.String</ReturnType>
411424
</ReturnValue>
412425
<Docs>
413-
<summary>Gets or sets a fully qualified path that represents the target of the attribute.</summary>
414-
<value>A fully qualified path that represents the target of the attribute.</value>
426+
<summary>Gets or sets a fully qualified path that represents the code analysis target.</summary>
427+
<value>A fully qualified path that represents the code analysis target.</value>
415428
<remarks>
416-
<format type="text/markdown"><![CDATA[
417-
418-
## Remarks
419-
The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.Target%2A> property is an optional argument identifying the analysis target of the attribute. An example value is "System.IO.Stream.ctor():System.Void". Because it is fully qualified, it can be long, particularly for targets such as parameters. The analysis tool user interface should be capable of automatically formatting the parameter.
420-
429+
<format type="text/markdown"><![CDATA[
430+
431+
## Remarks
432+
The <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.Target%2A> property is an optional argument identifying the analysis target of the attribute. An example value is "System.IO.Stream.ctor():System.Void". Because it is fully qualified, it can be long, particularly for targets such as parameters. The analysis tool user interface should be capable of automatically formatting the parameter.
433+
421434
]]></format>
422435
</remarks>
423436
</Docs>

0 commit comments

Comments
 (0)