次の方法で共有


Attribute.GetCustomAttribute メソッド (MemberInfo, Type, Boolean)

指定したクラス メンバに適用されている指定の型のカスタム属性、またはオプションで基本クラスから継承された指定の型のカスタム属性を取得します。

Overloads Public Shared Function GetCustomAttribute( _
   ByVal element As MemberInfo, _   ByVal attributeType As Type, _   ByVal inherit As Boolean _) As Attribute
[C#]
public static Attribute GetCustomAttribute(MemberInfoelement,TypeattributeType,boolinherit);
[C++]
public: static Attribute* GetCustomAttribute(MemberInfo* element,Type* attributeType,boolinherit);
[JScript]
public static function GetCustomAttribute(
   element : MemberInfo,attributeType : Type,inherit : Boolean) : Attribute;

パラメータ

  • element
    クラスのコンストラクタ メンバ、イベント メンバ、フィールド メンバ、メソッド メンバ、またはプロパティ メンバを記述する MemberInfo クラスから派生したオブジェクト。
  • attributeType
    カスタム属性を適用する対象の Type オブジェクト。
  • inherit
    true の場合は、 element の祖先のカスタム属性も検索することを示します。

戻り値

element に適用される attributeType 型のカスタム属性が存在しない場合は null 参照 (Visual Basic では Nothing) 。

または

element に適用される attributeType 型の単一のカスタム属性への Attribute 参照。

例外

例外の種類 条件
ArgumentNullException element または attributeType が null 参照 (Visual Basic では Nothing) です。
ArgumentException attributeTypeAttribute から派生していません。
NotSupportedException element がコンストラクタ、メソッド、プロパティ、イベント、型、またはフィールドではありません。
AmbiguousMatchException 要求された属性が複数見つかりました。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

Attribute クラス | Attribute メンバ | System 名前空間 | Attribute.GetCustomAttribute オーバーロードの一覧