This documentation is archived and is not being maintained.

CustomAttributeData Class

Provides access to custom attribute data for assemblies, modules, types, members and parameters that are loaded into the reflection-only context.


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

type CustomAttributeData =  class end

The CustomAttributeData type exposes the following members.

Protected methodCustomAttributeDataInitializes a new instance of the CustomAttributeData class.

Public propertyConstructorReturns a ConstructorInfo object representing the constructor that would have initialized the custom attribute.
Public propertyConstructorArgumentsGets the list of positional arguments specified for the attribute instance represented by the CustomAttributeData object.
Public propertyNamedArgumentsGets the list of named arguments specified for the attribute instance represented by the CustomAttributeData object.

Public methodEqualsReturns a value that indicates whether this instance is equal to a specified object. (Overrides Object.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodStatic memberGetCustomAttributes(Assembly)Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target assembly.
Public methodStatic memberGetCustomAttributes(MemberInfo)Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member.
Public methodStatic memberGetCustomAttributes(Module)Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target module.
Public methodStatic memberGetCustomAttributes(ParameterInfo)Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target parameter.
Public methodGetHashCodeServes as a hash function for a particular type. (Overrides Object.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string representation of the custom attribute. (Overrides Object.ToString().)

Code that is being examined in the reflection-only context cannot be executed, so it is not always possible to examine custom attributes by creating instances of them and then examining their properties, using methods like Attribute.GetCustomAttributes, MemberInfo.GetCustomAttributes, and so on. If the code for the attribute type itself is loaded into the reflection-only context, it cannot be executed.

The CustomAttributeData class allows examination of custom attributes in the reflection-only context by providing an abstraction for attributes. The members of this class can be used to obtain the positional arguments and named arguments of the attribute. Use the ConstructorArguments property to get a list of CustomAttributeTypedArgument structures that represent the positional arguments, and use the NamedArguments property to get a list of CustomAttributeNamedArgument structures that represent the named arguments.


The CustomAttributeNamedArgument structure only provides information about the attribute property used to get and set the argument value. To obtain the type and value of the argument, use the CustomAttributeNamedArgument.TypedValue property to obtain a CustomAttributeTypedArgument structure.

When you have a CustomAttributeTypedArgument structure for an argument, whether named or positional, use the CustomAttributeTypedArgument.ArgumentType property to get the type and the CustomAttributeTypedArgument.Value property to get the value.


For an array argument, the CustomAttributeTypedArgument.Value property returns a generic ReadOnlyCollection(T) of CustomAttributeTypedArgument objects. Each CustomAttributeTypedArgument object in the collection represents the corresponding element of the array.

CustomAttributeData can be used in the execution context as well as in the reflection-only context. For example, you might want to avoid loading the assembly that contains the code for a custom attribute. Using the CustomAttributeData class is different from using methods like Attribute.GetCustomAttributes:

  • The properties and methods of CustomAttributeData only provide you with the values that were specified for the attribute instance, not the semantics of the constructor. For example, a string argument of an attribute might be converted internally to some other representation, and returned in a canonical form; or a property might have side effects when the actual attribute code is executed.

  • The properties and methods of CustomAttributeData do not allow you to retrieve the custom attributes inherited from base classes.

To create instances of the CustomAttributeData class, use the static (Shared in Visual Basic) GetCustomAttributes factory methods.

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 information about the custom attributes that were applied to it and to the type and members it contains.

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

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.