Export (0) Print
Expand All

CustomAttributeData.GetCustomAttributes Method (Assembly)

Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target assembly.

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

static member GetCustomAttributes : 
        target:Assembly -> IList<CustomAttributeData> 

Parameters

target
Type: System.Reflection.Assembly

The assembly whose custom attribute data is to be retrieved.

Return Value

Type: System.Collections.Generic.IList(CustomAttributeData)
A list of objects that represent data about the attributes that have been applied to the target assembly.

ExceptionCondition
ArgumentNullException

target is a null reference (Nothing in Visual Basic).

This method provides an alternative to the GetCustomAttributes method that can always be used in the Reflection-only context.

The following example defines a custom attribute with four constructors and four properties. Two of the properties are read-only, and are set by using the positional parameters of the constructors. The other two properties are read/write, and can be set only by using named arguments. One positional property is an array of strings, and one named property is an array of integers.

The attribute is applied to the assembly, to a type declared in the assembly, to a method of the type, and to a parameter of the method. Different constructors are used for these cases. When executed, the assembly loads itself into the reflection-only context and displays the custom attributes.

The attribute that is applied to the type demonstrates array properties, with both positional and named arguments.

The GetCustomAttributes method is used in Main() to get the custom attributes applied to the assembly. The return value of the method is passed to the ShowAttributeData method.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft