Freigeben über


Assembly.GetCustomAttributes Method (Type, Boolean)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overridable Function GetCustomAttributes ( _
    attributeType As Type, _
    inherit As Boolean _
) As Object()
public virtual Object[] GetCustomAttributes(
    Type attributeType,
    bool inherit
)

Parameters

  • attributeType
    Type: System.Type
    The Type for which the custom attributes are to be returned.

Return Value

Type: array<System.Object[]
An array of type Object containing the custom attributes for this assembly as specified by attributeType.

Implements

ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

Exceptions

Exception Condition
ArgumentNullException

attributeType is nulla null reference (Nothing in Visual Basic).

ArgumentException

attributeType is not a runtime type.

MemberAccessException

The method is invoked late-bound through mechanisms such as Type.InvokeMember.

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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.