Provides access to custom attribute data for assemblies, modules, types, members and parameters that are loaded into the reflection-only context.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|AttributeType||Gets the type of the attribute.|
|Constructor||Gets a ConstructorInfo object that represents the constructor that would have initialized the custom attribute.|
|ConstructorArguments||Gets the list of positional arguments specified for the attribute instance represented by the object.|
|NamedArguments||Gets the list of named arguments specified for the attribute instance represented by the object.|
|Equals||Returns a value that indicates whether this instance is equal to a specified object. (Overrides Object.Equals(Object).)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetCustomAttributes(Assembly)||Returns a list of objects representing data about the attributes that have been applied to the target assembly.|
|GetCustomAttributes(MemberInfo)||Returns a list of objects representing data about the attributes that have been applied to the target member.|
|GetCustomAttributes(Module)||Returns a list of objects representing data about the attributes that have been applied to the target module.|
|GetCustomAttributes(ParameterInfo)||Returns a list of objects representing data about the attributes that have been applied to the target parameter.|
|GetHashCode||Serves as the default hash function. (Overrides Object.GetHashCode().)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns 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 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.
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 class is different from using methods like Attribute.GetCustomAttributes:
The properties and methods of 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 do not allow you to retrieve the custom attributes inherited from base classes.
To create instances of the 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.
Windows Phone 8.1, Windows Phone 8, 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.