次の方法で共有


Attribute.GetCustomAttribute メソッド (Assembly, Type)

指定したアセンブリに適用されている指定の型のカスタム属性、または基本クラスから継承された指定の型のカスタム属性を取得します。

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

パラメータ

  • element
    モジュールの再利用可能でバージョン管理可能なコレクションを記述する Assembly クラスから派生したオブジェクト。
  • attributeType
    カスタム属性を適用する対象の Type オブジェクト。

戻り値

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

または

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

例外

例外の種類 条件
ArgumentNullException element または attributeType が null 参照 (Visual Basic では Nothing) です。
ArgumentException attributeTypeAttribute から派生していません。
AmbiguousMatchException 要求された属性が複数見つかりました。

解説

複数の値を返す必要がある場合は、 GetCustomAttributes メソッドを使用します。そうしないと、 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, Common Language Infrastructure (CLI) Standard

参照

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