CustomAttributeExtensions.GetCustomAttribute Metodo

Definizione

Recupera un attributo personalizzato applicato a un elemento specificato.

Overload

GetCustomAttribute(Assembly, Type)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un assembly specificato.

GetCustomAttribute(MemberInfo, Type)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un membro specificato.

GetCustomAttribute(Module, Type)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un modulo specificato.

GetCustomAttribute(ParameterInfo, Type)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un parametro specificato.

GetCustomAttribute(MemberInfo, Type, Boolean)

Recupera un attributo personalizzato di un tipo specificato che viene applicato a un membro specificato e verifica facoltativamente i predecessori di tale membro.

GetCustomAttribute(ParameterInfo, Type, Boolean)

Recupera un attributo personalizzato di un tipo specificato che viene applicato a un parametro specificato e verifica facoltativamente i predecessori di tale parametro.

GetCustomAttribute<T>(ParameterInfo, Boolean)

Recupera un attributo personalizzato di un tipo specificato che viene applicato a un parametro specificato e verifica facoltativamente i predecessori di tale parametro.

GetCustomAttribute<T>(MemberInfo, Boolean)

Recupera un attributo personalizzato di un tipo specificato che viene applicato a un membro specificato e verifica facoltativamente i predecessori di tale membro.

GetCustomAttribute<T>(ParameterInfo)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un parametro specificato.

GetCustomAttribute<T>(Module)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un modulo specificato.

GetCustomAttribute<T>(MemberInfo)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un membro specificato.

GetCustomAttribute<T>(Assembly)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un assembly specificato.

GetCustomAttribute(Assembly, Type)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un assembly specificato.

C#
public static Attribute GetCustomAttribute (this System.Reflection.Assembly element, Type attributeType);
C#
public static Attribute? GetCustomAttribute (this System.Reflection.Assembly element, Type attributeType);

Parametri

element
Assembly

L'assembly da ispezionare.

attributeType
Type

Tipo di attributo da cercare.

Restituisce

Attributo personalizzato corrispondente a attributeType o null se questo attributo non viene trovato.

Eccezioni

element o attributeType è null.

attributeType non deriva da Attribute.

È stato trovato più di un attributo richiesto.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute(MemberInfo, Type)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un membro specificato.

C#
public static Attribute GetCustomAttribute (this System.Reflection.MemberInfo element, Type attributeType);
C#
public static Attribute? GetCustomAttribute (this System.Reflection.MemberInfo element, Type attributeType);

Parametri

element
MemberInfo

Il membro da ispezionare.

attributeType
Type

Tipo di attributo da cercare.

Restituisce

Attributo personalizzato corrispondente a attributeType o null se questo attributo non viene trovato.

Eccezioni

element o attributeType è null.

attributeType non deriva da Attribute.

element non è un costruttore, un metodo, una proprietà, un evento, un tipo o un campo.

È stato trovato più di un attributo richiesto.

Non è possibile caricare un tipo di attributo personalizzato.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute(Module, Type)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un modulo specificato.

C#
public static Attribute GetCustomAttribute (this System.Reflection.Module element, Type attributeType);
C#
public static Attribute? GetCustomAttribute (this System.Reflection.Module element, Type attributeType);

Parametri

element
Module

Modulo da controllare.

attributeType
Type

Tipo di attributo da cercare.

Restituisce

Attributo personalizzato corrispondente a attributeType o null se questo attributo non viene trovato.

Eccezioni

element o attributeType è null.

attributeType non deriva da Attribute.

È stato trovato più di un attributo richiesto.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute(ParameterInfo, Type)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un parametro specificato.

C#
public static Attribute GetCustomAttribute (this System.Reflection.ParameterInfo element, Type attributeType);
C#
public static Attribute? GetCustomAttribute (this System.Reflection.ParameterInfo element, Type attributeType);

Parametri

element
ParameterInfo

Il parametro da ispezionare.

attributeType
Type

Tipo di attributo da cercare.

Restituisce

Attributo personalizzato corrispondente a attributeType o null se questo attributo non viene trovato.

Eccezioni

element o attributeType è null.

attributeType non deriva da Attribute.

È stato trovato più di un attributo richiesto.

Non è possibile caricare un tipo di attributo personalizzato.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute(MemberInfo, Type, Boolean)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera un attributo personalizzato di un tipo specificato che viene applicato a un membro specificato e verifica facoltativamente i predecessori di tale membro.

C#
public static Attribute GetCustomAttribute (this System.Reflection.MemberInfo element, Type attributeType, bool inherit);
C#
public static Attribute? GetCustomAttribute (this System.Reflection.MemberInfo element, Type attributeType, bool inherit);

Parametri

element
MemberInfo

Il membro da ispezionare.

attributeType
Type

Tipo di attributo da cercare.

inherit
Boolean

true per ispezionare i predecessori di element; in caso contrario, false.

Restituisce

Attributo personalizzato corrispondente a attributeType o null se questo attributo non viene trovato.

Eccezioni

element o attributeType è null.

attributeType non deriva da Attribute.

element non è un costruttore, un metodo, una proprietà, un evento, un tipo o un campo.

È stato trovato più di un attributo richiesto.

Non è possibile caricare un tipo di attributo personalizzato.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute(ParameterInfo, Type, Boolean)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera un attributo personalizzato di un tipo specificato che viene applicato a un parametro specificato e verifica facoltativamente i predecessori di tale parametro.

C#
public static Attribute GetCustomAttribute (this System.Reflection.ParameterInfo element, Type attributeType, bool inherit);
C#
public static Attribute? GetCustomAttribute (this System.Reflection.ParameterInfo element, Type attributeType, bool inherit);

Parametri

element
ParameterInfo

Il parametro da ispezionare.

attributeType
Type

Tipo di attributo da cercare.

inherit
Boolean

true per ispezionare i predecessori di element; in caso contrario, false.

Restituisce

Attributo personalizzato che corrisponde a attributeType o a null se tale attributo non viene trovato.

Eccezioni

element o attributeType è null.

attributeType non deriva da Attribute.

È stato trovato più di un attributo richiesto.

Non è possibile caricare un tipo di attributo personalizzato.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute<T>(ParameterInfo, Boolean)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera un attributo personalizzato di un tipo specificato che viene applicato a un parametro specificato e verifica facoltativamente i predecessori di tale parametro.

C#
public static T GetCustomAttribute<T> (this System.Reflection.ParameterInfo element, bool inherit) where T : Attribute;
C#
public static T? GetCustomAttribute<T> (this System.Reflection.ParameterInfo element, bool inherit) where T : Attribute;

Parametri di tipo

T

Tipo di attributo da cercare.

Parametri

element
ParameterInfo

Il parametro da ispezionare.

inherit
Boolean

true per ispezionare i predecessori di element; in caso contrario, false.

Restituisce

T

Attributo personalizzato corrispondente a T o null se questo attributo non viene trovato.

Eccezioni

element è null.

element non è un costruttore, un metodo, una proprietà, un evento, un tipo o un campo.

È stato trovato più di un attributo richiesto.

Non è possibile caricare un tipo di attributo personalizzato.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute<T>(MemberInfo, Boolean)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera un attributo personalizzato di un tipo specificato che viene applicato a un membro specificato e verifica facoltativamente i predecessori di tale membro.

C#
public static T GetCustomAttribute<T> (this System.Reflection.MemberInfo element, bool inherit) where T : Attribute;
C#
public static T? GetCustomAttribute<T> (this System.Reflection.MemberInfo element, bool inherit) where T : Attribute;

Parametri di tipo

T

Tipo di attributo da cercare.

Parametri

element
MemberInfo

Il membro da ispezionare.

inherit
Boolean

true per ispezionare i predecessori di element; in caso contrario, false.

Restituisce

T

Attributo personalizzato corrispondente a T o null se questo attributo non viene trovato.

Eccezioni

element è null.

element non è un costruttore, un metodo, una proprietà, un evento, un tipo o un campo.

È stato trovato più di un attributo richiesto.

Non è possibile caricare un tipo di attributo personalizzato.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute<T>(ParameterInfo)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un parametro specificato.

C#
public static T GetCustomAttribute<T> (this System.Reflection.ParameterInfo element) where T : Attribute;
C#
public static T? GetCustomAttribute<T> (this System.Reflection.ParameterInfo element) where T : Attribute;

Parametri di tipo

T

Tipo di attributo da cercare.

Parametri

element
ParameterInfo

Il parametro da ispezionare.

Restituisce

T

Attributo personalizzato corrispondente a T o null se questo attributo non viene trovato.

Eccezioni

element è null.

element non è un costruttore, un metodo, una proprietà, un evento, un tipo o un campo.

È stato trovato più di un attributo richiesto.

Non è possibile caricare un tipo di attributo personalizzato.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute<T>(Module)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un modulo specificato.

C#
public static T GetCustomAttribute<T> (this System.Reflection.Module element) where T : Attribute;
C#
public static T? GetCustomAttribute<T> (this System.Reflection.Module element) where T : Attribute;

Parametri di tipo

T

Tipo di attributo da cercare.

Parametri

element
Module

Modulo da controllare.

Restituisce

T

Attributo personalizzato corrispondente a T o null se questo attributo non viene trovato.

Eccezioni

element è null.

È stato trovato più di un attributo richiesto.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute<T>(MemberInfo)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un membro specificato.

C#
public static T GetCustomAttribute<T> (this System.Reflection.MemberInfo element) where T : Attribute;
C#
public static T? GetCustomAttribute<T> (this System.Reflection.MemberInfo element) where T : Attribute;

Parametri di tipo

T

Tipo di attributo da cercare.

Parametri

element
MemberInfo

Il membro da ispezionare.

Restituisce

T

Attributo personalizzato corrispondente a T o null se questo attributo non viene trovato.

Eccezioni

element è null.

element non è un costruttore, un metodo, una proprietà, un evento, un tipo o un campo.

È stato trovato più di un attributo richiesto.

Non è possibile caricare un tipo di attributo personalizzato.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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

GetCustomAttribute<T>(Assembly)

Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs
Origine:
CustomAttributeExtensions.cs

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un assembly specificato.

C#
public static T GetCustomAttribute<T> (this System.Reflection.Assembly element) where T : Attribute;
C#
public static T? GetCustomAttribute<T> (this System.Reflection.Assembly element) where T : Attribute;

Parametri di tipo

T

Tipo di attributo da cercare.

Parametri

element
Assembly

L'assembly da ispezionare.

Restituisce

T

Attributo personalizzato corrispondente a T o null se questo attributo non viene trovato.

Eccezioni

element è null.

È stato trovato più di un attributo richiesto.

Commenti

Utilizzare il metodo di estensione GetCustomAttributes se si prevede più di un valore da restituire oppure verrà generata un'eccezione AmbiguousMatchException.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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