Assembly.GetCustomAttributes Method

Definition

Gets the custom attributes for this assembly.

Overloads

GetCustomAttributes(Boolean)

Gets all the custom attributes for this assembly.

GetCustomAttributes(Type, Boolean)

Gets the custom attributes for this assembly as specified by type.

GetCustomAttributes(Boolean)

Source:
Assembly.cs
Source:
Assembly.cs
Source:
Assembly.cs

Gets all the custom attributes for this assembly.

C#
public virtual object[] GetCustomAttributes(bool inherit);

Parameters

inherit
Boolean

This argument is ignored for objects of type Assembly.

Returns

Object[]

An array that contains the custom attributes for this assembly.

Implements

Remarks

This method implements the corresponding ICustomAttributeProvider interface method. Therefore, the inherit parameter must be specified even though it is ignored.

A pseudo-attribute indicates bits of the core metadata that must be set when the attribute is present. Unlike a custom attribute that extends the metadata for a type and is saved along with the type, a pseudo-attribute modifies the metadata for the type and then is discarded. Some of the resulting bits cannot be accessed using existing reflection APIs.

The following table summarizes the different pseudo-attributes and the accessors for the bits that are available in reflection.

Pseudo-Attribute Metadata Bits Reflection Accessor
DllImportAttribute CorPInvokeMap

DLL name
No accessor for PInvokeMap for ordinary method/global method attributes.

No accessor for DLL name.
GuidAttribute Stored as a real custom attribute. Accessed as a real custom attribute.
ComImportAttribute CorTypeAttr.tdImport Type.Attributes.Import
SerializableAttribute CorTypeAttr.tdSerializable Type.Attributes.Serializable
NonSerializedAttribute CorFieldAttr.fdNotSerialized FieldInfo.Attributes.NotSerialized
MethodImplAttribute CorMethodImpl MethodInfo.GetMethodImplementationFlags()

ConstructorInfo.GetMethodImplementationFlags()
MarshalAsAttribute Various bits. No accessor.
PreserveSigAttribute CorMethodImpl.miOLE MethodInfo.GetMethodImplementationFlags().OLE

ConstructorInfo.GetMethodImplementationFlags().OLE
InAttribute CorParamAttr.pdIn ParameterInfo.Attributes.In
OutAttribute CorParamAttr.pdOut ParameterInfo.Attributes.Out
StructLayoutAttribute CorTypeAttr.tdLayoutSequential

CorTypeAttr.tdExplicitLayout

CorTypeAttr.tdAnsiClass

CorTypeAttr.tdUnicodeClass

CorTypeAttr.tdAutoClass

Class packing.
Type.Attributes.LayoutSequential

Type.Attributes.ExplicitLayout

Type.Attributes.AnsiClass

Type.Attributes.UnicodeClass

Type.Attributes.AutoClass

No accessor.
FieldOffsetAttribute Field offset. No accessor.
AssemblyLoadAttribute CorAssemblyFlags No accessor or enumerator.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 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 2.0, 2.1

GetCustomAttributes(Type, Boolean)

Source:
Assembly.cs
Source:
Assembly.cs
Source:
Assembly.cs

Gets the custom attributes for this assembly as specified by type.

C#
public virtual object[] GetCustomAttributes(Type attributeType, bool inherit);

Parameters

attributeType
Type

The type for which the custom attributes are to be returned.

inherit
Boolean

This argument is ignored for objects of type Assembly.

Returns

Object[]

An array that contains the custom attributes for this assembly as specified by attributeType.

Implements

Exceptions

attributeType is null.

attributeType is not a runtime type.

Remarks

This method implements the corresponding ICustomAttributeProvider interface method. Therefore, the inherit parameter must be specified even though it is ignored.

A pseudo-attribute indicates bits of the core metadata that must be set when the attribute is present. Unlike a custom attribute that extends the metadata for a type and is saved along with the type, a pseudo-attribute modifies the metadata for the type and then is discarded. Some of the resulting bits cannot be accessed using existing reflection APIs.

The following table summarizes the different pseudo-attributes and the accessors for the bits that are available in reflection.

Pseudo-Attribute Metadata Bits Reflection Accessor
DllImportAttribute CorPInvokeMap

DLL name
No accessor for PInvokeMap for ordinary method/global method attributes.

No accessor for DLL name.
GuidAttribute Stored as a real custom attribute. Accessed as a real custom attribute.
ComImportAttribute CorTypeAttr.tdImport Type.Attributes.Import
SerializableAttribute CorTypeAttr.tdSerializable Type.Attributes.Serializable
NonSerializedAttribute CorFieldAttr.fdNotSerialized FieldInfo.Attributes.NotSerialized
MethodImplAttribute CorMethodImpl MethodInfo.GetMethodImplementationFlags()

ConstructorInfo.GetMethodImplementationFlags()
MarshalAsAttribute Various bits. No accessor.
PreserveSigAttribute CorMethodImpl.miOLE MethodInfo.GetMethodImplementationFlags().OLE

ConstructorInfo.GetMethodImplementationFlags().OLE
InAttribute CorParamAttr.pdIn ParameterInfo.Attributes.In
OutAttribute CorParamAttr.pdOut ParameterInfo.Attributes.Out
StructLayoutAttribute CorTypeAttr.tdLayoutSequential

CorTypeAttr.tdExplicitLayout

CorTypeAttr.tdAnsiClass

CorTypeAttr.tdUnicodeClass

CorTypeAttr.tdAutoClass

Class packing.
Type.Attributes.LayoutSequential

Type.Attributes.ExplicitLayout

Type.Attributes.AnsiClass

Type.Attributes.UnicodeClass

Type.Attributes.AutoClass

No accessor.
FieldOffsetAttribute Field offset. No accessor.
AssemblyLoadAttribute CorAssemblyFlags No accessor or enumerator.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 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 2.0, 2.1