SuppressMessageAttribute クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<AttributeUsageAttribute(AttributeTargets.All, Inherited:=False, AllowMultiple:=True)> _ <ConditionalAttribute("CODE_ANALYSIS")> _ Public NotInheritable Class SuppressMessageAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.All, Inherited=false, AllowMultiple=true)] [ConditionalAttribute("CODE_ANALYSIS")] public sealed class SuppressMessageAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::All, Inherited=false, AllowMultiple=true)] [ConditionalAttribute(L"CODE_ANALYSIS")] public ref class SuppressMessageAttribute sealed : public Attribute

![]() |
---|
ConditionalAttribute は、属性呼び出しを含めるか省略するかを決定する条件シンボルとしてプリプロセス シンボル "CODE_ANALYSIS" を指定して、このクラスに適用されます。シンボルが定義されている場合、属性呼び出しが含められ、それ以外の場合は省略されます。
|

SuppressMessageAttribute 属性を使用して警告メッセージの実行を抑制する方法を次のコード例に示します。
#Const CODE_ANALYSIS = True Imports System Imports System.Diagnostics.CodeAnalysis Class Library <SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters", 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
#define CODE_ANALYSIS using System; using System.Diagnostics.CodeAnalysis; namespace CodeAnalysisSample { class Library { [SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters", MessageId = "isChecked")] [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "fileIdentifier")] static void FileNode(string name, bool isChecked) { string fileIdentifier = name; string fileName = name; string version = String.Empty; } } }

System.Attribute
System.Diagnostics.CodeAnalysis.SuppressMessageAttribute


Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SuppressMessageAttribute コンストラクタ
アセンブリ: mscorlib (mscorlib.dll 内)

Dim category As String Dim checkId As String Dim instance As New SuppressMessageAttribute(category, checkId)

category パラメータ値は分析ツールに固有の値であり、checkId パラメータによって識別された規則を分類します。2 つのパラメータが連結されて、規則に対する一意の識別子が作られます。
![]() |
---|
プリプロセッサ シンボル "CODE_ANALYSIS" をこの属性に対して定義して、有効にする必要があります。プリプロセッサ シンボルがない場合、属性は適用されません。 |

SuppressMessageAttribute 属性を使用し、Microsoft.Performance カテゴリ、およびチェック識別子の CA1801 と CA1804 に対する警告を抑制するコード例を次に示します。このコード例は、SuppressMessageAttribute クラスのトピックで取り上げているコード例の一部分です。
<SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters", 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
[SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters", MessageId = "isChecked")] [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "fileIdentifier")] static void FileNode(string name, bool isChecked) { string fileIdentifier = name; string fileName = name; string version = String.Empty; }

Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SuppressMessageAttribute プロパティ
SuppressMessageAttribute メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

SuppressMessageAttribute メンバ
特定の静的分析ツール規則違反の報告を抑制します。1 つのコードで複数の抑制を実行できます。
SuppressMessageAttribute データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | SuppressMessageAttribute | 静的分析ツールのカテゴリおよび分析規則の識別子を指定して、SuppressMessageAttribute クラスの新しいインスタンスを初期化します。 |


名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

- SuppressMessageAttributeのページへのリンク