SuppressMessageAttribute クラス

定義

特定のコード分析規則違反の報告を非表示にし、1 つのコードの成果物で複数の非表示を可能にします。 コンパイラ 診断には適用されません。

public ref class SuppressMessageAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true, Inherited=false)]
[System.Diagnostics.Conditional("CODE_ANALYSIS")]
public sealed class SuppressMessageAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true, Inherited=false)>]
[<System.Diagnostics.Conditional("CODE_ANALYSIS")>]
type SuppressMessageAttribute = class
    inherit Attribute
Public NotInheritable Class SuppressMessageAttribute
Inherits Attribute
継承
SuppressMessageAttribute
属性

次のコード例は、 属性を使用してパフォーマンス警告 SuppressMessageAttribute メッセージを抑制する方法を示しています。

#define CODE_ANALYSIS
using System;
using System.Diagnostics.CodeAnalysis;

namespace CodeAnalysisSample
{
    class Library
    {
        [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", 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;
        }
    }
}
#Const CODE_ANALYSIS = True
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
End Class

注釈

この属性は、任意のアプリケーション要素に適用できます。 抑制できる違反の完全な一覧については、「 コード品質規則」を参照してください。

注意

ConditionalAttributeは、属性呼び出しを含めるか省略するかを決定する条件付きシンボルとして前処理シンボル "CODE_ANALYSIS" を指定して、このクラスに適用されます。 シンボルが定義されている場合は、属性呼び出しが含まれます。それ以外の場合、呼び出しは省略されます。

Visual Studio でコード分析の警告を右クリックし、[抑制ファイル] で [ルール ID>> の抑制<] または [ソース (属性)] の [ルール ID の抑制<] を>>選択すると、SuppressMessage 属性がグローバル抑制ファイルまたはソース コード ファイルに追加されます。 SuppressMessage 属性と Visual Studio での使用の詳細については、「コード分析違反を抑制する」を参照してください。

コンストラクター

SuppressMessageAttribute(String, String)

コード分析ツールのカテゴリおよび分析規則の識別子を指定して、SuppressMessageAttribute クラスの新しいインスタンスを初期化します。

プロパティ

Category

属性の分類を識別するカテゴリを取得します。

CheckId

非表示にするコード分析ツール規則の識別子を取得します。

Justification

コード分析メッセージの抑制に関する位置合わせを取得または設定します。

MessageId

展開された除外条件を取得または設定します。

Scope

属性に関係するコードのスコープを取得または設定します。

Target

コード分析ターゲットを表す完全修飾パスを取得または設定します。

TypeId

派生クラスで実装されると、この Attribute の一意の識別子を取得します。

(継承元 Attribute)

メソッド

Equals(Object)

このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。

(継承元 Attribute)
GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 Attribute)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象