Export (0) Print
Expand All

SuppressMessageAttribute Class

Suppresses reporting of a specific static analysis tool rule violation, allowing multiple suppressions on a single code artifact.

Namespace: System.Diagnostics.CodeAnalysis
Assembly: mscorlib (in mscorlib.dll)

'Declaration
<AttributeUsageAttribute(AttributeTargets.All, Inherited:=False, AllowMultiple:=True)> _
<ConditionalAttribute("CODE_ANALYSIS")> _
Public NotInheritable Class SuppressMessageAttribute
	Inherits Attribute
'Usage
Dim instance As SuppressMessageAttribute

/** @attribute AttributeUsageAttribute(AttributeTargets.All, Inherited=false, AllowMultiple=true) */ 
/** @attribute ConditionalAttribute("CODE_ANALYSIS") */ 
public final class SuppressMessageAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.All, Inherited=false, AllowMultiple=true) 
ConditionalAttribute("CODE_ANALYSIS") 
public final class SuppressMessageAttribute extends Attribute
Not applicable.

This attribute can be applied to any application element.

NoteNote:

The 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.

The following code example shows the use of the SuppressMessageAttribute attribute to suppress performance warning messages.

#Const CODE_ANALYSIS = True
Imports System
Imports System.Diagnostics.CodeAnalysis



Class Library
    
    <SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId:="isChecked"), _
     SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId:="fileIdentifier")> _
    Shared Sub FileNode(ByVal name As String, ByVal isChecked As Boolean)
        Dim fileIdentifier As String = name
        Dim fileName As String = name
        Dim version As String = String.Empty

    End Sub 'FileNode
End Class 'Library 

System.Object
   System.Attribute
    System.Diagnostics.CodeAnalysis.SuppressMessageAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2015 Microsoft