System.Reflection.CustomAttributeData Class

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

See Also: CustomAttributeData Members


public class CustomAttributeData


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 erload:System.Attribute.GetCustomAttributes, erload:System.Reflection.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 System.Reflection.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 CustomAttributeData.ConstructorArguments property to get a list of System.Reflection.CustomAttributeTypedArgument structures that represent the positional arguments, and use the CustomAttributeData.NamedArguments property to get a list of System.Reflection.CustomAttributeNamedArgument structures that represent the named arguments.


The System.Reflection.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 System.Reflection.CustomAttributeTypedArgument structure.

When you have a System.Reflection.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 System.Collections.ObjectModel.ReadOnlyCollection`1 of System.Reflection.CustomAttributeTypedArgument objects. Each System.Reflection.CustomAttributeTypedArgument object in the collection represents the corresponding element of the array.

System.Reflection.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 System.Reflection.CustomAttributeData class is different from using methods like erload:System.Attribute.GetCustomAttributes:

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


Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions:,
Since: .NET 2.0