CustomAttributeTypedArgument Structure
Collapse the table of content
Expand the table of content

CustomAttributeTypedArgument Structure

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Represents an argument of a custom attribute in the reflection-only context, or an element of an array argument.

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

public struct CustomAttributeTypedArgument

The CustomAttributeTypedArgument type exposes the following members.

Public propertyArgumentTypeGets the type of the argument or of the array argument element.
Public propertyValueGets the value of the argument for a simple argument or for an element of an array argument; gets a collection of values for an array argument.

Public methodEqualsIndicates whether this instance and a specified object are equal. (Inherited from ValueType.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeReturns the hash code for this instance. (Inherited from ValueType.)
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 the fully qualified type name of this instance. (Inherited from ValueType.)

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 CustomAttributeNamedArgument structure is used by the CustomAttributeData class to provide access to the type and value of a positional argument specified for a custom attribute instance, without executing the attribute constructor. It also provides access to the type and value of a named argument without executing the code of the corresponding property of the custom attribute type.

The types and values of all the positional and named arguments of an attribute instance are provided by CustomAttributeTypedArgument structures. The positional attributes returned by the CustomAttributeData.ConstructorArguments property are directly represented by CustomAttributeTypedArgument structures, but the named arguments returned by the CustomAttributeData.NamedArguments property are represented by CustomAttributeNamedArgument structures; to get the CustomAttributeTypedArgument structure for a named argument, use the CustomAttributeNamedArgument.TypedValue property.

If an argument is an array of values, the Value property of the CustomAttributeTypedArgument that represents the argument returns a generic ReadOnlyCollection<T> of CustomAttributeTypedArgument objects. Each CustomAttributeTypedArgument object in the collection represents the corresponding element of the array.

To create instances of the CustomAttributeData class, use the staticGetCustomAttributes() factory method.

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.

Windows Phone OS

Supported in: 8.1, 8.0

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

© 2017 Microsoft