CustomAttributeExtensions.GetCustomAttribute メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定された要素に適用されるカスタム属性を取得します。
GetCustomAttribute(Assembly, Type) |
指定されたアセンブリに適用される指定された型のカスタム属性を取得します。 |
GetCustomAttribute(MemberInfo, Type) |
指定したメンバーに適用される指定した型のカスタム属性を取得します。 |
GetCustomAttribute(Module, Type) |
指定されたモジュールに適用される指定された型のカスタム属性を取得します。 |
GetCustomAttribute(ParameterInfo, Type) |
指定したパラメーターに適用される指定した型のカスタム属性を取得します。 |
GetCustomAttribute(MemberInfo, Type, Boolean) |
指定したメンバーに適用される指定した型のカスタム属性を取得し、オプションでそのメンバーの先祖を調べます。 |
GetCustomAttribute(ParameterInfo, Type, Boolean) |
指定したパラメーターに適用される指定した型のカスタム属性を取得し、オプションでそのパラメーターの先祖を調べます。 |
GetCustomAttribute<T>(ParameterInfo, Boolean) |
指定したパラメーターに適用される指定した型のカスタム属性を取得し、オプションでそのパラメーターの先祖を調べます。 |
GetCustomAttribute<T>(MemberInfo, Boolean) |
指定したメンバーに適用される指定した型のカスタム属性を取得し、オプションでそのメンバーの先祖を調べます。 |
GetCustomAttribute<T>(ParameterInfo) |
指定したパラメーターに適用される指定した型のカスタム属性を取得します。 |
GetCustomAttribute<T>(Module) |
指定されたモジュールに適用される指定された型のカスタム属性を取得します。 |
GetCustomAttribute<T>(MemberInfo) |
指定したメンバーに適用される指定した型のカスタム属性を取得します。 |
GetCustomAttribute<T>(Assembly) |
指定されたアセンブリに適用される指定された型のカスタム属性を取得します。 |
指定されたアセンブリに適用される指定された型のカスタム属性を取得します。
public:
[System::Runtime::CompilerServices::Extension]
static Attribute ^ GetCustomAttribute(System::Reflection::Assembly ^ element, Type ^ attributeType);
public static Attribute GetCustomAttribute (this System.Reflection.Assembly element, Type attributeType);
public static Attribute? GetCustomAttribute (this System.Reflection.Assembly element, Type attributeType);
static member GetCustomAttribute : System.Reflection.Assembly * Type -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As Assembly, attributeType As Type) As Attribute
パラメーター
- element
- Assembly
調べるアセンブリ。
- attributeType
- Type
検索する属性の種類。
戻り値
attributeType
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
または attributeType
が null
です。
attributeType
は Attribute から派生していません。
要求された属性が複数見つかりました。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定したメンバーに適用される指定した型のカスタム属性を取得します。
public:
[System::Runtime::CompilerServices::Extension]
static Attribute ^ GetCustomAttribute(System::Reflection::MemberInfo ^ element, Type ^ attributeType);
public static Attribute GetCustomAttribute (this System.Reflection.MemberInfo element, Type attributeType);
public static Attribute? GetCustomAttribute (this System.Reflection.MemberInfo element, Type attributeType);
static member GetCustomAttribute : System.Reflection.MemberInfo * Type -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As MemberInfo, attributeType As Type) As Attribute
パラメーター
- element
- MemberInfo
調べるメンバー。
- attributeType
- Type
検索する属性の種類。
戻り値
attributeType
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
または attributeType
が null
です。
attributeType
は Attribute から派生していません。
element
がコンストラクター、メソッド、プロパティ、イベント、型、またはフィールドではありません。
要求された属性が複数見つかりました。
カスタム属性の型を読み込むことはできません。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定されたモジュールに適用される指定された型のカスタム属性を取得します。
public:
[System::Runtime::CompilerServices::Extension]
static Attribute ^ GetCustomAttribute(System::Reflection::Module ^ element, Type ^ attributeType);
public static Attribute GetCustomAttribute (this System.Reflection.Module element, Type attributeType);
public static Attribute? GetCustomAttribute (this System.Reflection.Module element, Type attributeType);
static member GetCustomAttribute : System.Reflection.Module * Type -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As Module, attributeType As Type) As Attribute
パラメーター
- element
- Module
調べるモジュール。
- attributeType
- Type
検索する属性の種類。
戻り値
attributeType
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
または attributeType
が null
です。
attributeType
は Attribute から派生していません。
要求された属性が複数見つかりました。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定したパラメーターに適用される指定した型のカスタム属性を取得します。
public:
[System::Runtime::CompilerServices::Extension]
static Attribute ^ GetCustomAttribute(System::Reflection::ParameterInfo ^ element, Type ^ attributeType);
public static Attribute GetCustomAttribute (this System.Reflection.ParameterInfo element, Type attributeType);
public static Attribute? GetCustomAttribute (this System.Reflection.ParameterInfo element, Type attributeType);
static member GetCustomAttribute : System.Reflection.ParameterInfo * Type -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As ParameterInfo, attributeType As Type) As Attribute
パラメーター
- element
- ParameterInfo
調べるパラメーター。
- attributeType
- Type
検索する属性の種類。
戻り値
attributeType
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
または attributeType
が null
です。
attributeType
は Attribute から派生していません。
要求された属性が複数見つかりました。
カスタム属性の型を読み込むことはできません。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定したメンバーに適用される指定した型のカスタム属性を取得し、オプションでそのメンバーの先祖を調べます。
public:
[System::Runtime::CompilerServices::Extension]
static Attribute ^ GetCustomAttribute(System::Reflection::MemberInfo ^ element, Type ^ attributeType, bool inherit);
public static Attribute GetCustomAttribute (this System.Reflection.MemberInfo element, Type attributeType, bool inherit);
public static Attribute? GetCustomAttribute (this System.Reflection.MemberInfo element, Type attributeType, bool inherit);
static member GetCustomAttribute : System.Reflection.MemberInfo * Type * bool -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As MemberInfo, attributeType As Type, inherit As Boolean) As Attribute
パラメーター
- element
- MemberInfo
調べるメンバー。
- attributeType
- Type
検索する属性の種類。
- inherit
- Boolean
element
の先祖を調べる場合は true
。それ以外の場合は false
。
戻り値
attributeType
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
または attributeType
が null
です。
attributeType
は Attribute から派生していません。
element
がコンストラクター、メソッド、プロパティ、イベント、型、またはフィールドではありません。
要求された属性が複数見つかりました。
カスタム属性の型を読み込むことはできません。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定したパラメーターに適用される指定した型のカスタム属性を取得し、オプションでそのパラメーターの先祖を調べます。
public:
[System::Runtime::CompilerServices::Extension]
static Attribute ^ GetCustomAttribute(System::Reflection::ParameterInfo ^ element, Type ^ attributeType, bool inherit);
public static Attribute GetCustomAttribute (this System.Reflection.ParameterInfo element, Type attributeType, bool inherit);
public static Attribute? GetCustomAttribute (this System.Reflection.ParameterInfo element, Type attributeType, bool inherit);
static member GetCustomAttribute : System.Reflection.ParameterInfo * Type * bool -> Attribute
<Extension()>
Public Function GetCustomAttribute (element As ParameterInfo, attributeType As Type, inherit As Boolean) As Attribute
パラメーター
- element
- ParameterInfo
調べるパラメーター。
- attributeType
- Type
検索する属性の種類。
- inherit
- Boolean
element
の先祖を調べる場合は true
。それ以外の場合は false
。
戻り値
attributeType
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
または attributeType
が null
です。
attributeType
は Attribute から派生していません。
要求された属性が複数見つかりました。
カスタム属性の型を読み込むことはできません。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定したパラメーターに適用される指定した型のカスタム属性を取得し、オプションでそのパラメーターの先祖を調べます。
public:
generic <typename T>
where T : Attribute[System::Runtime::CompilerServices::Extension]
static T GetCustomAttribute(System::Reflection::ParameterInfo ^ element, bool inherit);
public static T GetCustomAttribute<T> (this System.Reflection.ParameterInfo element, bool inherit) where T : Attribute;
public static T? GetCustomAttribute<T> (this System.Reflection.ParameterInfo element, bool inherit) where T : Attribute;
static member GetCustomAttribute : System.Reflection.ParameterInfo * bool -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As ParameterInfo, inherit As Boolean) As T
型パラメーター
- T
検索する属性の種類。
パラメーター
- element
- ParameterInfo
調べるパラメーター。
- inherit
- Boolean
element
の先祖を調べる場合は true
。それ以外の場合は false
。
戻り値
T
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
が null
です。
element
がコンストラクター、メソッド、プロパティ、イベント、型、またはフィールドではありません。
要求された属性が複数見つかりました。
カスタム属性の型を読み込むことはできません。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定したメンバーに適用される指定した型のカスタム属性を取得し、オプションでそのメンバーの先祖を調べます。
public:
generic <typename T>
where T : Attribute[System::Runtime::CompilerServices::Extension]
static T GetCustomAttribute(System::Reflection::MemberInfo ^ element, bool inherit);
public static T GetCustomAttribute<T> (this System.Reflection.MemberInfo element, bool inherit) where T : Attribute;
public static T? GetCustomAttribute<T> (this System.Reflection.MemberInfo element, bool inherit) where T : Attribute;
static member GetCustomAttribute : System.Reflection.MemberInfo * bool -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As MemberInfo, inherit As Boolean) As T
型パラメーター
- T
検索する属性の種類。
パラメーター
- element
- MemberInfo
調べるメンバー。
- inherit
- Boolean
element
の先祖を調べる場合は true
。それ以外の場合は false
。
戻り値
T
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
が null
です。
element
がコンストラクター、メソッド、プロパティ、イベント、型、またはフィールドではありません。
要求された属性が複数見つかりました。
カスタム属性の型を読み込むことはできません。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定したパラメーターに適用される指定した型のカスタム属性を取得します。
public:
generic <typename T>
where T : Attribute[System::Runtime::CompilerServices::Extension]
static T GetCustomAttribute(System::Reflection::ParameterInfo ^ element);
public static T GetCustomAttribute<T> (this System.Reflection.ParameterInfo element) where T : Attribute;
public static T? GetCustomAttribute<T> (this System.Reflection.ParameterInfo element) where T : Attribute;
static member GetCustomAttribute : System.Reflection.ParameterInfo -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As ParameterInfo) As T
型パラメーター
- T
検索する属性の種類。
パラメーター
- element
- ParameterInfo
調べるパラメーター。
戻り値
T
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
が null
です。
element
がコンストラクター、メソッド、プロパティ、イベント、型、またはフィールドではありません。
要求された属性が複数見つかりました。
カスタム属性の型を読み込むことはできません。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定されたモジュールに適用される指定された型のカスタム属性を取得します。
public:
generic <typename T>
where T : Attribute[System::Runtime::CompilerServices::Extension]
static T GetCustomAttribute(System::Reflection::Module ^ element);
public static T GetCustomAttribute<T> (this System.Reflection.Module element) where T : Attribute;
public static T? GetCustomAttribute<T> (this System.Reflection.Module element) where T : Attribute;
static member GetCustomAttribute : System.Reflection.Module -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As Module) As T
型パラメーター
- T
検索する属性の種類。
パラメーター
- element
- Module
調べるモジュール。
戻り値
T
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
が null
です。
要求された属性が複数見つかりました。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定したメンバーに適用される指定した型のカスタム属性を取得します。
public:
generic <typename T>
where T : Attribute[System::Runtime::CompilerServices::Extension]
static T GetCustomAttribute(System::Reflection::MemberInfo ^ element);
public static T GetCustomAttribute<T> (this System.Reflection.MemberInfo element) where T : Attribute;
public static T? GetCustomAttribute<T> (this System.Reflection.MemberInfo element) where T : Attribute;
static member GetCustomAttribute : System.Reflection.MemberInfo -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As MemberInfo) As T
型パラメーター
- T
検索する属性の種類。
パラメーター
- element
- MemberInfo
調べるメンバー。
戻り値
T
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
が null
です。
element
がコンストラクター、メソッド、プロパティ、イベント、型、またはフィールドではありません。
要求された属性が複数見つかりました。
カスタム属性の型を読み込むことはできません。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
指定されたアセンブリに適用される指定された型のカスタム属性を取得します。
public:
generic <typename T>
where T : Attribute[System::Runtime::CompilerServices::Extension]
static T GetCustomAttribute(System::Reflection::Assembly ^ element);
public static T GetCustomAttribute<T> (this System.Reflection.Assembly element) where T : Attribute;
public static T? GetCustomAttribute<T> (this System.Reflection.Assembly element) where T : Attribute;
static member GetCustomAttribute : System.Reflection.Assembly -> 'T (requires 'T :> Attribute)
<Extension()>
Public Function GetCustomAttribute(Of T As Attribute) (element As Assembly) As T
型パラメーター
- T
検索する属性の種類。
パラメーター
- element
- Assembly
調べるアセンブリ。
戻り値
T
に一致するカスタム属性。該当する属性が見つからない場合は null
。
例外
element
が null
です。
要求された属性が複数見つかりました。
注釈
複数の値を返すことが予想される場合は、GetCustomAttributes 拡張メソッドを使用します。このメソッドを使用しないと、AmbiguousMatchException がスローされます。
適用対象
.NET 9 およびその他のバージョン
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。